WIN32 : how to list the current processes by their executable name?

Roger Upole rupole at compaq.net
Tue Jan 18 00:50:32 EST 2000


There is a win32pdhutil module in the win32 library, with a function
FindPerformanceAttributesByName.
Given an executable name, it will return a list of matching pids, which are
then at your mercy.

"Yann SAMAMA" <ysamama at cybercable.fr> wrote in message
news:85vur9$1prj$1 at news5.isdnet.net...
> Hi everybody!!
>
> Is there a simple way to implement an os.kill() that works on all WIN32
> platforms?
> I know about the FAQ article, but I want the kill function to take the
name
> of the executable file as parameter, not the Process ID.
>
> It should work like this :
>
>
> def kill(exe_file):
> # assumes we're on a Win 32 platform
>     import win32api
>
>     mylist = getcurrentprocesses(exe_file)  # that's the key function, it
> retrieves a list of corresponding PID
>
> # if exec_file is "myprog.exe", we kill all instances of this program that
> are actually running...
>
>     for pid in mylist:
>         handle = win32api.OpenProcess(1, 0, pid)   # that's the FAQ
> implementation of kill function
>         win32api.TerminateProcess(handle, 0)
>
>
> Any idea about how writing this function "getcurrentprocesses()" ?
>
>
> I've heard about a POSIX port of "kill" on NT that accepts a file name
> with -f option, but I'm afraid I won't be allowed to install it on my NT
> platform...
>
> Thanks in advance,
>
> Yann.
>
>





More information about the Python-list mailing list