[python-win32] How to get command line parameters of running processes via pywin32

Patrick Li patrick at gxlinc.com
Wed Dec 5 19:04:20 CET 2007


I am interested in scanning the user's process table periodically and
getting the list of running process names as well as their command line

For the process names, I am able to get the list of pids using
win32process.EnumProcesses and then use win32api.OpenProcess and
win32process.GetModuleFileNameEx to get the names.  However, I couldn't find
anywhere in the doc that tells me how to get the command line parameters for
them as well.

Then I found the WMI module on
http://tgolden.sc.sabren.com/python/wmi_cookbook.html#running_processes that
seems to do the trick:

import wmi
c = wmi.WMI ()
for process in c.Win32_Process ():
  print process.CommandLine

Is that the most efficient way to get the command line parameters?  My
program will need to scan the process table quite often, so I am trying to
make this operation as lightweight as noticeable.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20071205/b1421600/attachment.htm 

More information about the python-win32 mailing list