Re: win32 process name

Discussion in 'Python' started by Andrey Ivanov, Dec 22, 2004.

  1. [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
    Andrey Ivanov, Dec 22, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rtm
    Replies:
    0
    Views:
    788
  2. Java and Swing
    Replies:
    1
    Views:
    661
    Chris Lambacher
    Oct 24, 2005
  3. Tim Golden
    Replies:
    0
    Views:
    428
    Tim Golden
    Oct 21, 2005
  4. Qi Lu
    Replies:
    0
    Views:
    393
    Qi Lu
    Jul 14, 2008
  5. Mike Stead
    Replies:
    3
    Views:
    262
    Roger Pack
    Mar 25, 2010
Loading...

Share This Page