Automating old DOS application using Python - python

Is there a way to automate an old DOS application (16-bit, probably needs an emulator such as DOSBox) from Python (on Windows)? I would like to send keys and strings to the application, detect updates to the DOS "screen" and get the application output.
It would be even better if the DOS application could run "hidden", i.e., not showing in the taskbar.
Note: It is not a game, it is one of those old application where you are given menus with press 1 for something, press 2 for something else, etc... then it asks for some input numbers, and then it shows some results. It is a pure console application.
Note2: It doesn't need to use DOSBox necessarily... could be done with other emulators such as Bochs

I'm not familiar with DosBOX or whether it has an external API. However, for Sun VirtualBox there is a python API, so if it is OK to run DOS on a VM, you could easily use the VirtualBox Python API to control & automate the application you run on the DOS.
You can download the VirtualBox SDK here

Related

Handling remote (RDP) mouse clicking via Python

I am using pyautogui to automate some mouse clicking in a script that I created.
This script needs to perform one click to log into a program, nothing else (besides other non-clicking stuff). The idea is that the script will run on a remote Win10 PC via a task scheduler every day at, lets say, at 11PM.
My script works perfectly when run on my own PC but I am running into issues with how to handle the remote RDP resolution to correctly identify the mouse position to click. Furthermore, the script will run on a remote PC that might not have "active user" logged in and I am not even sure if this mouse clicking approach will work. How to identify correctly the "resolution" of the remote PC?
Could you help me?
Thanks.
Pyautogui can be used to interact with remote system the same way a human can by opening the RDP or VNC window identifying elements inside of it and then directly interacting with them. This works but you're now expecting two systems to be in sufficiently consistent state for the automation to work. This does have the advantage that you don't need to know the resolution of the remote system just what the interactable elements look like when rendered through the RDP client on your system.

sending mouse/keyboard events on remote desktop

So I am trying to set up a Continuous integration environment using Jenkins.
One of the build step requires a series of mouse actions/movements to accomplish a task in Excel. I have already written a python script using the ctypes library to do this.
The script works perfectly fine if I run it either through Jenkins or on the server itself when I am actively logged in to the server using remote desktop connection, but as soon as I minimize/close the connection and then run the script from Jenkins, it seems the mouse events never get executed. Is there something I can add to the script to make this work? Thanks for any help you can provide.

How to make a VirtualBox window go to fullscreen mode from python?

I am working with the VirtualBox python API and am trying to open a VM window in fullscreen mode. I have been unable to find an API command to do so, so I am trying to use the win32api to send a keyboard command of F8+f (F8 is my host key since there is no SendKeys code for Right Control) to the application, but am not succeeding in this endeavor. My code follows, any ideas?
import time,win32api,win32con,win32com
shell = win32com.client.Dispatch("WScript.Shell")
#The title of the application was copied from the Task Manager
shell.AppActivate("fed (Snapple) [Running] - Oracle VM VirtualBox")
win32api.Sleep(100)
shell.SendKeys("({F8}f)")
hey check this out ..may be it helps you..
This is pyVBOX, a shim layer above the VirtualBox Python API.
Why? Becuase the VirtualBox Python API is somewhat complex and I got
tried of trying to remember all the details of its use. Plus it
changes from release to release and this gives me an abstraction layer
to hide those changes. The software also includes a script,
utils/pyVbox.py, that provides the ability to manipulate VMs (like
VBoxMange).
This code is written to the 4.1 version of VirtualBox (4.1.12
specifically). I have not tried it against any other version.
This software is independently created from VirtualBox and Oracle. No
endorsement by Oracle or the VirtualBox authors is implied.
pyVbox

UI Automation Windows User login

I have a test case where i have to automate user action on windows UI,
The scenario is that windows password has expired, and when user tries to login to the
system, the reset password page appears and user inputs new password and login succeeds.
Now i have to do this through a script,
Good thing is i have a python service running on the machine to which i can pass commands if required prior to login.
I have Googled a lot but could not find anything similar.
Would be very glad if anyone can point me to anything specific to my problem,
What should be my reference point for this UI automation??
If you're trying to automate the Windows logon UI, I believe it's possible, but it requires that you use a Windows service to run your test code. Sounds like you may already be doing that, since you mentioned a Python service you can use to run commands while no user is logged in to Windows.
Anyway, Windows services are the only way I know to do this (without disabling UAC or otherwise modifying the default Windows security configuration).
See my answer to this question for some pointers:
UAC and remote control
If your Python code is running with the privileges of a Windows service, it should be able to interact with any UI on the system (or at least launch other processes that can interact with secure UI), including the Windows logon desktop.
The only headache may be that in order to interact with the Winlogon desktop, your test code may need to launch a separate program with the CreateProcessAsUser function (and pass "Winsta0\Winlogon" as the desktop param). Not sure, though.
This answer also looks like it might be helpful in your situation:
Running a process at the Windows 7 Welcome Screen

How can I create an local webserver for my python scripts?

I'm looking to use a local webserver to run a series of python scripts for the user. For various unavoidable reasons, the python script must run locally, not on a server. As a result, I'll be using HTML+browser as the UI, which I'm comfortable with, for the front end.
I've been looking, therefore, for a lightweight web server that can execute python scripts, sitting in the background on a machine, ideally as a Windows service. Security and extensibility are not high priorities as it's all running internally on a small network.
Should I run a native python webserver as a Windows service (in which case, how)? Or is it just as easy to install Apache onto the user's machine and run as CGI? Since this is all local, performance is not an issue either.
Or am I missing something obvious?
Don't waste a lot of time creating Windows service.
Don't waste a lot of time on Windows Apache.
Just make a Python service that responds to HTTP requests.
Look at https://docs.python.org/2/library/basehttpserver.html
https://docs.python.org/3/library/http.server.html for version 3
Python offers an HTTP server that you can extend with your server-side methods.
Look at http://docs.python.org/library/wsgiref.html
Python offers a WSGI reference implementation that makes your server easy and standards-compliant.
Also http://fragments.turtlemeat.com/pythonwebserver.php
"I'm trying to avoid making the user run python stuff from the command prompt."
I don't see how clicking a web page is any different from clicking desktop icons.
Starting a web server based on Python is relatively easy, once you have the web server. First, build the server. Later, you can make sure the server starts. Let's look at some ways.
Your user can't use a random browser to open your local page. They need a bookmark to launch "localhost:8000/myspecialserverinsteadofthedestop/" That bookmark can be a .BAT file that (1) runs the server, (2) runs firefox with the proper initial URL.
You can put the server in the user's start-this menu.
You can make your Python program a windows "service".
Best way is to make your own local server by using command prompt.
Make a new folder say Project
Make a new folder inside project & name it as "cgi-bin"(without quotes)
Paste your .py file inside the cgi-bin folder
Open cmd and change to the directory from which you want to run the server and type "python -m CGIHTTPServer"(without quotes)
Minimize the cmd window & open your browser and type "localhost:8000/cgi-bin/yourpythonfilename.py"(without quotes).
The wasiest step would be navigate to folder where your files are located and running http.server module
cd /yourapp
python3 -m http.server
the you should see something like this in console
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
Running a native python webserver as a windows service should be a no brainer. Check out the documentation for writing windows services (win32api, ActiveState python) in python and also the documentation for subclassing BaseHttpServer and SimpleHttpServer.
BTW: I had a similar question on stackoverflow: How to stop BaseHTTPServer.serve_forever() in a BaseHTTPRequestHandler subclass?
Basically, you subclass BaseHTTPServer (you have to anyway...) and then... but just read the accepted answer - it set me on the right track!

Categories

Resources