[python-win32] Any way to get PyHANDLE for any running process?
Brett C.
bac at OCF.Berkeley.EDU
Fri Jul 2 12:53:20 EDT 2004
Moore, Paul wrote:
> 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 :-)
>
Thanks to Paul, Jens, and Tim for replying to my email. With two
suggestions being the same as above I will give that a shot.
And yes, as I have quickly learned from my novice experience with coding
for Windows, it would be a novelty if it was in any way simple.
-Brett
More information about the Python-win32
mailing list