Using PyWinAuto to control a currently running application - python

Using the following code I can find that the currently running window I want to connect is named "Trade Monitor" how do i successfull connect to it? Using the app.start_ method does not work.
from pywinauto import application
app=application.Application
app.findwindows #prints all windows running on machine
app.window("Trade Monitor") #error

Just use app = Application().connect(title='Trade Monitor', timeout=10).
More detailed info is in the docs here.

Related

Is there a way to send ISPF commands and get job statistics using python script on Mainframe?

I'm trying to automate some manual tasks on Mainframe using python script and to do that I need job status.. I know there is FTP library to login mainframe but I'm not able to send commands and get job statistics.. please suggest if there is any documentation..
Thanks in advance!
Not sure exactly what you're after concerning "job statistics", but there are a set of APIs provided by z/OSMF that can be invoked from any REST requester. A jobs interface is included. Docs on these APIs are found here: https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.1.0/com.ibm.zos.v2r1.izua700/IZUHPINFO_RESTServices.htm
z/OSMF must be installed on your z/OS system before using this; it's not always there. Your systems programmer should know whether it's up, running and usable and whether you would have authority to use those services.

Getting data generated in putty Application using COM objects in python

I am trying to write application which uses WSH scripting under Python for automation purpose. I used win32com.client module to get shell and run the putty application to access routers. Iam able to access the devices and send the key strokes and commands to putty GUI window. But the problem is,I want to track the ongoing command status which was sent using COM object.How can I read/get the buffer data of application initiated by COM object.Is there any easy way?Can I can get the data in python variable which is returned by device in putty ! Please help..`
import time
import win32api
import win32com.client
shell = win32com.client.gencache.EnsureDispatch("WScript.Shell")
shell.Run("putty")
time.sleep(1)
shell.SendKeys("192.168.1.x")
shell.SendKeys(r"show version | no-more") #command to run on putty
console
time.sleep(2)
shell.SendKeys("~")
Thanks,
Sat

Automating a process in windows

We have a web application which alerts when a server refresh is needed. When the alert comes we have to open a windows application,give the server name & refresh the server. Can this process be automated by using any scripting languages?
You alert system could launch a python script. For example take a look here for a simple way to launch a python script when outlook gets an email.
Then you can use pywinauto, it has a very simple API:
from pywinauto import application
app = application.Application.start("notepad.exe")
app.Notepad.MenuSelect("Help->About Notepad")
app.AboutNotepad.OK.Click()
app.Notepad.Edit.TypeKeys ("pywinauto Works!", with_spaces = True)
Also see: Why write yet another automation tool if there are so many out there? for a comparison with other existing tools.

Run Python application from browser

I'm pretty new to programming and I've been learning python in my spare time. As a challenge to myself, I created a simple text adventure for a class project. This is not for a programming class, so the professor won't know how to compile a raw Python script, let alone have a Python interpreter on their Mac.
That being said, is it possible to run python from a browser? I'm imagining some HTML file that my professor, or anyone, can click that launches a browser and they can play my game from there.
I've learned about something called Django from my research on this subject. However, I have no idea what it is, nor how to implement it. Again, I'm pretty new to programming, so if you could "explain like I'm five", that would be great.
EDIT: I found this other thread where the OP asks a similar question, but I don't fully understand the approved answer:
execution python application from browser
Well, not really. Your basic browser generally supports 1 programming language, javascript.
However, you could use pythonanywhere" which is a hosted python environment.
You could also try skulpt which is a javacript implementation of python. I have never tried this myself.
You can host a website on an internal network and run the program from there. Read more about the Python CGI programming
here to make a form that will execute your script and print the result as a html page
For example you could have a form that will ask for input in textboxes: Name: _, Value: __, SUBMIT
After they press the button, the browser will then send a request to the python program, execute it, and display the result back to the client as a html webpage.
In addition, you do not need to install any other third-party modules if you are using a school computer. However, ask you teacher before hosting the website on the school network.
The problem is that your program is a "text adventure" which requires a lot more input/output management for a CGI program.
You can use this answer for other projects.
Anyway, here are the steps to setup the server:
1) Create a folder for your website and add a "index.html" file (it can be anything)
2) Add a favicon.ico file in the folder (this will speed up the connection) You can download this one
3) Put this python program in the folder (it will be used to host the website)
import BaseHTTPServer
import CGIHTTPServer
import cgitb; cgitb.enable()
from socket import gethostbyname, gethostname
def server(port):
server = BaseHTTPServer.HTTPServer
handler = CGIHTTPServer.CGIHTTPRequestHandler
server_address = ("", port)
httpd = server(server_address, handler)
print "Server %s:%s started" % (gethostbyname(gethostname()), str(port))
httpd.serve_forever()
server(4) #You can change this. It is a port number
4) Create a cgi-bin folder
5) To make the website available, execute the program created in the step 3. To stop hosting it, just close the python console.
6) While the program is running, you can go into the browser and type the IP adress : port as the URL. You will see your index.html page and favicon.ico icon. Anyone who is connected to the same network can get to the website. You and only you can also get to the website in a browser by entering http:/localhost:port with "port" being the port you've set
7) The rest you need to manage yourself. I cannot create the full script because I do not know what is in your program. Read the link provided in the beginning and modify your program to make it work in the browser.
FYI: It is possible to host more than one website or an instance of the same website at once using different ports. And, you can set and read cookies using Python CGI
Please comment if something doesn't work because of an error in my answer. I will try to fix it.
All of the answers so far assume that your game is something that can be presented as a web app. You can only do that if you write or covert your program (or part of it) into Javascript, which may not actually work because the existing compilers (e.g. pyjs) are quite limited.
If you made your program in a GUI (using 'Tkinter', 'Pygame', wxPython, PyQt, etc.), your best option is to package your program into a Mac app using py2app or pyinstaller.

How can I use python to read windows eventlog from a remote machine?

I'm working on retrieving the Windows eventlog from a remote machine using Python.
I tried the following code:
import win32evtlog
server = 'aRemoteMachineHostName'
logtype = 'System'
hand = win32evtlog.OpenEventLog(server,logtype)
total = win32evtlog.GetNumberOfEventLogRecords(hand)
and I get an access denied error.
Then I tried use win32security.Logon to do the authentication before I access the eventlog.
But I find in the win32security.Logon document, it says the API only supports local logon.
So, I'm a little bit stuck here. I wonder whether Python can do a remote Windows logon?
Any tips or hints will be helpful.
Thanks.
might be easier to use snmp
As long as the user who is executing the script has the credentials to connect and read the event log, this ActiveState Recipe works for me. I've used it in a few different situations.
ActiveState WinEvtLogViewer

Categories

Resources