Is a win32 process running using the pid.

Tim Golden tim.golden at viacom-outdoor.co.uk
Tue Feb 3 14:54:43 CET 2004


>-----Original Message-----
>From: guy.flowers at Machineworks.com 
>[mailto:guy.flowers at Machineworks.com]
>Sent: 03 February 2004 11:53
>To: python-list at python.org
>Subject: Is a win32 process running using the pid.
>
>
>Hi, I created a function, which seems to work, quite well, it tells me
>if a process is running in widows using the pid number (I'm aware that
>the pid number in widows is not called a pid and this is really a unix
>thing but what the hell). The function keeps crashing (I've included
>the crash but I don't think it will do any good.), only sometimes,
>most of the time it works fine and I don't know why, Could any body
>suggest anything, maybe someone has a stable function that can do the
>below :
>

[... snip crash and function details ...]

Oh my goodness! Perhaps I've misunderstood, but if
all you want to do is see if a process with a particular
id is running, it's got to be easier than that. I would
have thought that something would be possible using
win32process, although nothing jumps out at me.

Certainly you can do it using WMI. A naive function
would look something like this:

<code>
import wmi
c = wmi.WMI ()

def is_this_process_running (id):
  return len (c.Win32_Process (ProcessId=id))
</code>

Something slightly more sophisticated could use
a WMI event. Something like this, perhaps:
http://tgolden.sc.sabren.com/python/wmi_cookbook.html#watch_notepad

Sorry if I've misunderstood your intention. Hope it helps.
TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________




More information about the Python-list mailing list