win32 process name

Andrey Ivanov ai2009 at yandex.ru
Wed Dec 22 10:27:31 CET 2004


[phil]

> I need to know if a process is running.
> not just python.exe
> but python.exe myapp

> from win32all
> EnumProcesses gives me the pids, then
> OpenProcess(pid) gives me a handle.
> Then what?
> GetModuleFileNameEX?

It   won't   do   the   right  thing  for  you.  As  far  as  I  know,
GetModuleFileNameEx()  returns  the name of a particular DLL, but what
you need to know is a *commandline*. I think that this is not possible
at  all.  Microsoft's  examples  use named mutexes to test whether the
process  is  already running or not. It is quite easy. Here's a quick
example:

import sys
import win32event

STANDARD_ACCESS_READ = 131072

mutex_handle = None

try:
    mutex_handle = win32event.OpenMutex(STANDARD_ACCESS_READ, False, "Test")
except:
    pass

if mutex_handle:
    sys.exit("Instance is already running")
else:
    mutex_handle = win32event.CreateMutex(None, False, "Test")

try:
    while 1:
        pass
except:
    pass


-- 
Andrey




More information about the Python-list mailing list