开发者

How would I go about killing a process/application?

开发者 https://www.devze.com 2023-03-05 11:33 出处:网络
I\'d like to be able to kill various programs mid-run using python. How would I go about this? Something like this:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消