Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List running processes on 64-bit Windows

I amm writing a little python script that will grab information from VMs of Windows that I am running.

At the moment I can list the processes on a 32bit XP machine with the following method:

http://code.activestate.com/recipes/305279/

Is it possible to somehow detect the version of windows running and excute a different method for getting the processes on a 64bit machine, I am trying to get the processes from a 64Bit Vista and 64bit Windows 7.

Any ideas?

like image 706
RailsSon Avatar asked Oct 27 '09 16:10

RailsSon


People also ask

How do I see all processes running in Windows?

Task Manager can be opened in a number of ways, but the simplest is to select Ctrl+Alt+Delete, and then select Task Manager. In Windows, first click More details to expand the information displayed. From the Processes tab, select Details to see the process ID listed in the PID column.

How can I tell if a process is running 64-bit?

In the Processes tab, you see the list of processes that are running at the moment. If a program is 32-bit, near its name you should see the text: *32. If a program is 64-bit, you only see its name, without *32 at the end.

How can I see what processes are running?

Hold Ctrl+Shift+Esc or right-click on the Windows bar, and choose Start Task Manager. In Windows Task Manager, click on More details. The Processes tab displays all running processes and their current resources usage. To see all processes executed by an individual user, go to the Users tab (1), and expand User (2).


2 Answers

The cleanest way I found to solve this was to use the psutil library as recommended by Robert Lujo:

psutil.process_iter()

Note that it returns a generator object, issuing a process object at a time. For example if you need the list of process names, you can do something like:

[p.name() for p in psutil.process_iter()]
like image 120
jonathanrocher Avatar answered Oct 13 '22 12:10

jonathanrocher


There is another recipe on activestate that does a similar thing, but uses the Performance Data Helper library (PDH) instead.

I have tested this on my Windows 7 64bit machine and it works there - so presumably the same function will work on both 32bit and 64 bit windows.

You can find the recipe here: http://code.activestate.com/recipes/303339/

Another method is using WMI, there is an example here in Python using the wmi module:

http://timgolden.me.uk/python/wmi/cookbook.html

import wmi
c = wmi.WMI ()

for process in c.Win32_Process ():
  print process.ProcessId, process.Name
like image 43
Andre Miller Avatar answered Oct 13 '22 13:10

Andre Miller