Retrieve Command Line arguments

  • Thread starter Thread starter Rich Smith
  • Start date Start date
R

Rich Smith

Is there a way to get the Command Line Arguments of a running process?

myProcess.StartInfo.Arguments is empty and doesn't work.
I am looking to find the Arguments for any process that is already
running including ones that I did not personally start.

Here is what I can get so far...

Process[] runningProcesses = Process.GetProcesses();
foreach(Process process in runningProcesses)
{
Console.WriteLine(process.StartTime.ToLongTimeString());
Console.WriteLine(process.ProcessName);
Console.WriteLine(process.MainModule.FileName);
Console.WriteLine(process.MainWindowTitle);
Console.WriteLine(process.MainModule.FileVersionInfo.FileVersion);
}
 
Rich,
You should be able to get what you want by calling Environment.CommandLine.
Please let me know if this worked for you.

--
Thanks.
Paulo

DISCLAIMER: This posting is provided "AS IS" with no warranties, and confers
no rights. Use of any included code samples are subject to the terms
specified at http://www.microsoft.com/info/cpyright.htm"
 
Paulo Lisboa said:
You should be able to get what you want by calling Environment.CommandLine.

That only provides the command line for the *current* process. The OP
wnats access to the command line for *other* processes.
 
Paulo said:
You should be able to get what you want by calling Environment.CommandLine.
Please let me know if this worked for you.

Environment.CommandLine only retrieves the arguments of
the "current process". I want to retrieve the arguments
for ANY running process.

I can get a bunch of information already such as their
MainWindowTitle and Executable Path but not the
command line arguments.

So for "ping.exe" or any other process I want to retrieve
its command line arguments.
 
Back
Top