Getting the command line switches for processes.

  • Thread starter Thread starter Frank Rizzo
  • Start date Start date
F

Frank Rizzo

I am looping through the array of processes returned by
Process.GetProcesses(). How do I get the command line parameters that
each of the processes was started with? Kind of like in the
SysInternals' Process Explorer?

I've tried Process.StartInfo.Arguments property but it is always empty.

Thanks.
 
|I am looping through the array of processes returned by
| Process.GetProcesses(). How do I get the command line parameters that
| each of the processes was started with? Kind of like in the
| SysInternals' Process Explorer?
|
| I've tried Process.StartInfo.Arguments property but it is always empty.
|
| Thanks.

Using System.Management and WMI, here is a sample:

SelectQuery selectQuery = new SelectQuery("select * from
Win32_Process");
using(ManagementObjectSearcher searcher = new
ManagementObjectSearcher(selectQuery))
{
foreach(ManagementObject process in searcher.Get())
{
string commandLine = process.Properties["CommandLine"].Value;
Console.WriteLine(commandLine);
}
}

Note that you need administaror privileges to get the process properties of
all running processes!

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top