[python-win32] Monitoring a running Windows program

Troy Sorzano pythonwin32@infopackaging.com
Thu, 01 Nov 2001 14:46:52 EST


Hi Jens,

Thanks for the pointer.  I spent lots of time wrestling with MSDN and the 
win32pdh help documents but finally got it working.  I am sure this is not 
the best way to do this but it does work.  I hope this example will save 
time for someone in the future.


import win32pdh
import win32api

list = win32pdh.EnumObjectItems(None, None , 'Process' , 
win32pdh.PERF_DETAIL_WIZARD , 0 )

x = 'notepad' in list[1] 

if x == 1:
    print "  Notepad Is Running"
else:
    print "  Notepad Is Not Running......Starting Now"
    win32api.WinExec('notepad')


Later,

Troy


> You can get a list of processes from the windows performance counters 
> api. Take a look in the MSDN Library for this. Then use the win32pdh 
> module to get the data.
> 
> Troy Sorzano wrote:
> 
> >Hi All,
> >
> >I am new to python and trying to create a simple EXE monitor.  As you 
> >know windows programs are not very stable.  I have one such app that I 
> >would like to have a python script monitor.  If it is not running then 
> >my script will start it up using ShellExecute.  If it is running then 
> >do nothing.  I am trying to use some info I found on the Microsoft 
> >technet web site.  It suggests:
> >
> >"Using the Windows API function GetModuleUsage, your program can 
> >monitor the status of a shelled process.  The return value from Shell, 
> >can be used to call GetModuleUsage continuously within a loop to poll 
> >whether or not the shelled program has finished executing."
> >
> >Problem is I can't find GetModuleUsage in the Win32.  Is there another 
> >way to monitor Windows executables?
> >
> >Thanks,
> >
> >Troy Sorzano
> >
> >
> >
> >
> >
> >_______________________________________________
> >Python-win32 mailing list
> >Python-win32@python.org
> >http://mail.python.org/mailman/listinfo/python-win32
> >
> 
> -- 
> Jens B. Jorgensen
> jens.jorgensen@tallan.com
>



Sent using Virtual Access 5.51 - download your freeware copy now
http://www.atlantic-coast.com/downloads/vasetup.exe