views:

552

answers:

2

Hey Guys,

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?

Cheers

Eef

A: 

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.

Dana the Sane
+2  A: 

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
Andre Miller
WMI works well for this
Corey Goldberg
Does WMI work on 64bit windows also? I can not see anything on there site that mentions 64bit, or do you use the same method names?
Eef
It should work the same way (including method) names for both environments.
Andre Miller