Checking processes running under Windows
Shane Geiger
sgeiger at ncee.net
Thu Mar 27 11:23:47 EDT 2008
One way: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303339
Another way: wmi
# List all running processes
# http://tgolden.sc.sabren.com/python/wmi_cookbook.html#running_processes
import wmi
c = wmi.WMI ()
for process in c.Win32_Process ():
print process.ProcessId, process.Name
# List all running notepad processes
import wmi
c = wmi.WMI ()
for process in c.Win32_Process (name="notepad.exe"):
print process.ProcessId, process.Name
# Create and then destroy a new notepad process
import wmi
c = wmi.WMI ()
process_id, return_value = c.Win32_Process.Create
(CommandLine="notepad.exe")
for process in c.Win32_Process (ProcessId=process_id):
print process.ProcessId, process.Name
result = process.Terminate ()
João Rodrigues wrote:
> Hello all! I'm trying to write a script that needs to check which
> processes are running under Windows (XP Pro, Home, whatever). The
> method I'm using is:
>
> >>> process_list = os.popen('TASKLIST').read()
>
> However, XP Home doesn't have the tasklist.exe tool so, this is kind
> of useless in that OS. Do you have any other methods I can use for this?
>
> Thanks!
--
Shane Geiger
IT Director
National Council on Economic Education
sgeiger at ncee.net | 402-438-8958 | http://www.ncee.net
Leading the Campaign for Economic and Financial Literacy
More information about the Python-list
mailing list