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:
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.
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:
import wmi c = wmi.WMI () for process in c.Win32_Process (): print process.ProcessId, process.Name
If you don’t want to rely on any extra installed modules then you can parse the output of wmic, e.g.:
c:> wmic process get description,executablepath ... explorer.exe C:Windowsexplorer.exe cmd.exe C:WindowsSysWOW64cmd.exe conhost.exe C:Windowssystem32conhost.exe ...
For similar purposes I have used psutil library. Some hints:
- list processes with
- inspect process information with
process = psutil.Process(pid)(reference)
The cleanest way I found to solve this was to use the psutil library as recommended by Robert Lujo:
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()]
You should be able to do this by exposing Windows Management Instrumentation within each VM. This tool gives you access to a bunch of system data, including processes, see http://technet.microsoft.com/en-us/library/cc757287%28WS.10%29.aspx
You should be able to
popen one of the commands in the preceding link to get the info you’re looking for.