Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   How to detect open windows applications (http://www.velocityreviews.com/forums/t335878-how-to-detect-open-windows-applications.html)

Roy 09-16-2004 02:55 PM

How to detect open windows applications
 
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.

Tim Golden 09-16-2004 07:46 PM

Re: How to detect open windows applications
 
Roy wrote:
> 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

=?iso-8859-1?Q?Michel_Claveau_-_abstraction_m=E9ta-galactique_non_trivial?==?iso-8859-1?Q?e_en_fuite 09-16-2004 07:49 PM

Re: How to detect open windows applications
 
Hi !

Search the process.

@-salutations
--
Michel Claveau



Roy 09-17-2004 01:37 PM

Re: How to detect open windows applications
 
That sounds like a good way...
How do I get a list of the process?

Michel Claveau - abstraction méta-galactique non trivial e en fuite perpétuelle. <unseulmcmcmcmc@msupprimerlepoint.claveauPOINTco m> wrote in message news:<cicqq6$kra$1@news-reader4.wanadoo.fr>...
> Hi !
>
> Search the process.
>
> @-salutations


gh@ghaering.de 09-17-2004 01:49 PM

Re: How to detect open windows applications
 
On Fri, Sep 17, 2004 at 06:37:02AM -0700, Roy wrote:
> 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

Roy 09-17-2004 03:59 PM

Re: How to detect open windows applications
 
Michel Claveau - abstraction méta-galactique non trivial e en fuite perpétuelle. <unseulmcmcmcmc@msupprimerlepoint.claveauPOINTco m> wrote in message news:<cicqq6$kra$1@news-reader4.wanadoo.fr>...
> 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!


All times are GMT. The time now is 06:01 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.