Posts tagged ‘Processes’

Getting Arguments from a Running Process

If you get all the running processes using .NET, the Process.StartInfo.Arguments will be empty.

var processes = Process.GetProcessesByName( "MyProcess" );

This seems a little odd, but whatever, let’s find a workaround. Here is some code to get the arguments of a process.

var managementObjectSearcher = new ManagementObjectSearcher( "select CommandLine from Win32_Process where Name='MyProcess.exe'" );
var managementObjects = managementObjectSearcher.Get();
foreach( var managementObject in managementObjects )
{
    var command = (string)managementObject["CommandLine"];
}

Command is the full command line used to start the process. This includes the path and all arguments.