[python-win32] Any way to get PyHANDLE for any running process?

Moore, Paul Paul.Moore at atosorigin.com
Fri Jul 2 11:06:37 EDT 2004


From: Brett Cannon
> I noticed win32process.TerminateProcess(), but it wants a PyHANDLE and I 
> can't figure out how to create one for any process other than the 
> currently running one.

> Any help on this would be great.  Already sick of doing it manually 
> through the Task Manager.

If you don't need to use Python, Systems Internals' pstools package at
http://www.sysinternals.com/ntw2k/freeware/pstools.shtml includes a
pskill utility - pskill iexplore will kill all iexplore processes.

Otherwise, you need stuff from the win32process module. You can use
win32process.EnumProcesses to get all processes and then win32api.OpenProcess
to convert a pid to a pyHandle, then win32process.GetModuleFileNameEx
with a hModule of 0 to get the executable name. Once you have that, you
can decide whether it's the one you want to kill...

Maybe there's a simpler way, but that would be a bit of a novelty when
dealing with the Win32 API :-)

Hope this helps,
Paul.


__________________________________________________________________________
This e-mail and the documents attached are confidential and intended 
solely for the addressee; it may also be privileged. If you receive this 
e-mail in error, please notify the sender immediately and destroy it.
As its integrity cannot be secured on the Internet, the Atos Origin group 
liability cannot be triggered for the message content. Although the 
sender endeavours to maintain a computer virus-free network, the sender 
does not warrant that this transmission is virus-free and will not be 
liable for any damages resulting from any virus transmitted.
__________________________________________________________________________



More information about the Python-win32 mailing list