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

Yann SAMAMA ysamama at cybercable.fr
Mon Jan 17 15:41:25 EST 2000


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