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

Stefan Migowsky smigowsky at dspace.de
Tue Jan 18 03:54:40 EST 2000


Hi,

see the example given by Mark Hammond in the win32 package

...\Python\win32\scripts\killProcName.py

Stefan

>-----Original Message-----
>From: Yann SAMAMA [mailto:ysamama at cybercable.fr]
>Sent: Monday, January 17, 2000 8:47 PM
>To: python-list at python.org
>Subject: WIN32 : how to list the current processes by their executable
>name?
>
>
>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.
>
>
>-- 
>http://www.python.org/mailman/listinfo/python-list
>




More information about the Python-list mailing list