[python-win32] Finding and Exiting a Process
Tim Golden
tim.golden at viacom-outdoor.co.uk
Mon Sep 20 10:55:36 CEST 2004
[Lewis Franklin]
| I have a program I have developed that opens a custom VB script. I
| want to be able to start and end the script; however, the script
| actually spawns a new program and therefore has a new process ID.
| Unfortunately, due to the nature of the script, the VB script cannot
| be rewritten.
|
| My question is if there is any way to find the process ID of the new
| program, either by capturing it when it is spawned or by somehow
| identifying the process (I do know the program name of the spawned
| program if that somehow helps).
If I understand you, you have a python program which launches
an external VB program (not clear if it matters that it is VB;
presumably it's an .EXE file). You want to know what that
spawned process is to be able to terminate it?
If that's it, then one way (which I haven't used) is to use
ShellExecuteEx from win32com.shell.shell. That will return a
process handle which you can then wait on etc. If that's not
an option, there are ways of trawling the process list to
find a running program by name etc.
Here's one from the Python Cookbook:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305279
Another way is WMI:
http://tgolden.sc.sabren.com/python/wmi_cookbook.html#watch_notepad
Trent Mick's process package might help:
http://starship.python.net/~tmick/index.html#process
... or the module formerly known as popen5:
http://www.lysator.liu.se/~astrand/popen5/
Or, failing that, you can try Simon Brunning's techniques
for finding open windows/controls by name:
http://www.brunningonline.net/simon/blog/archives/000664.html
HTH
TJG
________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
More information about the Python-win32
mailing list