To get process information for both NT and W2K (but not the 9x family) you can use the Performance Data Helper library(PDH). The is a simple example that shows you how to get a process list and their ids. It provides a convenient interface to performance information stored fundamentally in the registry. The basic process of using the PDH encompasses the following:
In the case here we want the process object, the object's instances are it's list of processes, and the counter we want for the processes is 'ID Process'.
Python, 27 lines
A whole sequence of calls are necessary to get process information. 1. PdhOpenQuery -- initialize query handle which contains ID Process counter 2. PdhMakeCounterPath -- make path for counter 3. PdhAddCounter -- group the counters paths together for the query 4. PdhCollectQueryData -- gathers the actual data 5. PdhGetFormattedCounterValue -- convert data to typical format 6. PdhCloseQuery -- close the counters and the query handle
Compared to similar C++ code to do the same thing, the python code is very clean. You can learn about more details about Performance Data Helper library by consulting http://msdn.microsoft.com.