How to detect open windows applications

R

Roy

How do I know within my python script if a specific windows
application is currently running in Windows 2000. Specifically, I
would like to know of MSWORD is running. I have the win32 package
installed. Thank you for your help.
 
T

Tim Golden

Roy said:
How do I know within my python script if a specific windows
application is currently running in Windows 2000. Specifically, I
would like to know of MSWORD is running. I have the win32 package
installed. Thank you for your help.

I'm sure there are other ways, but since no-one else has
replied yet, you could use wmi:

<code>
import wmi

c = wmi.WMI ()
for p in c.Win32_Process (Name="thunderbird.exe"):
print p.ExecutablePath

</code>

The example uses my wmi-wrapper module (Google for Python
WMI) but you can do WMI with raw pywin32 -- all the module
does is to make life a bit easier.

TJG
 
G

gh

That sounds like a good way...
How do I get a list of the process?

That's possible with the win32 extensions. For a quick hack I often prefer to
interface command-line utilities like the pulist.exe and kill.exe from the M$
Resource Kit.

-- Gerhard
 
R

Roy

Michel Claveau - abstraction méta-galactique non trivial e en fuite perpétuelle. said:
Hi !

Search the process.

@-salutations

I found it! (I think)
Is the following code reasonable?
......
import win32pdh

processes = win32pdh.EnumObjectItems(None, None, "Process", -1)
processList = list(processes[1])

app = 'WINWORD'
try:
index = processList.index(app)
print "Application %s is running." % app
except ValueError:
print "Application %s is not running." % app
......
I don't care about index, which indicates where it is in the process list.

Thank you for your help!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top