[python-win32] How to get command line parameters of running processes via pywin32
Tim Roberts
timr at probo.com
Wed Dec 5 19:30:02 CET 2007
Patrick Li wrote:
>
> 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 parameters.
>
> 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.
That's the only way. The command line is stored in the process' private
memory; there is no API to go fetch it.
Why do you need to get this information "quite often"? What problem are
you solving? What you describe is going to be a resource-intensive
operation.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the python-win32
mailing list