I'd like to be able to kill various programs mid-run using python. How would I go about this?
Something like this:
module.end_process('chrome.exe')
This little bit of code would shut down Google Chrome.
This is in W开发者_Python百科indows 7, BTW.
http://docs.python.org/library/os.html#os.kill
os.kill()
Although, you have to have the PID to use os.kill()- I'm not sure how to find a PID from a proc name with windows.
You need to use Python Win32 Extensions to handle Win32 processes from Python. You can use the approach explained in this mail thread to find out handle of the executable (process) which you want to kill. You can then pass the obtained handle to method win32Process.TerminateProcess
to kill the application.
精彩评论