Getting Process Name on Win32

Stefan Rank stefan.rank at ofai.at
Wed Sep 6 13:13:26 CEST 2006


[BTW, there is a list/newsgroup specifically for pywin32]

on 06.09.2006 12:56 Rama said the following:
> Hi,
>  
>      I want to list the names of all the processes running on my 
> machine. I am stuck at this point and do not know how to extract the 
> name of a process.
> 
>      Using win32process.EnumProcesses, I am able to obtain the pids of 
> all the processes and using win32api.OpenProcess() I have obtained a 
> handle to the process. However, I could not find an appropriate method 
> to provide me the name of the process. I went through the available 
> documentation on the 
> http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/pywin32/win32.html 
> site - but could not find something to help me.
> 
>      Could some one please guide me on this?

This is not directly what you wanted, but it works for me::

   In [1]: import win32com.client

   In [2]: wmi = win32com.client.GetObject('winmgmts:')

   In [3]: procs = wmi.ExecQuery('Select * from win32_process')

   In [4]: for proc in procs:
      ...:     print proc.Name
      ...:
   System Idle Process
   ... [censored]


There are also python-packages that encapsulate dealing with wmi.

cheers,
stefan




More information about the Python-list mailing list