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" );
view raw File1.cs hosted with ❤ by GitHub

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"];
view raw File2.cs hosted with ❤ by GitHub

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

Leave a Reply