In my Win7 Task Manager, there's a column that can be displayed called "Command Line" and will show exactly how the process was started and all the parameters issued. If I have a Process
object for a currently running process that I did not start, how can I get that information? I had hoped that I could do something like p.StartInfo.Arguments
but that's always coming back as an empty string. The entire StartInfo
property seems empty, probably because I did not start the process I'm querying. I'm guessing that I'm going to have to use a WinAPI call.
To set command-line arguments in Visual Studio, right click on the project name, then go to Properties. In the Properties Pane, go to "Debugging", and in this pane is a line for "Command-line arguments." Add the values you would like to use on this line.
Each argument on the command line is separated by one or more spaces, and the operating system places each argument directly into its own null-terminated string. The second parameter passed to main() is an array of pointers to the character strings containing each argument (char *argv[]).
All the command line arguments are stored in a character pointer array called argv[ ].
Well you could use WMI, there is a class that could be queryied to retrieve the process list and each object contains also a property for the command line that started the process
string query = "SELECT Name, CommandLine, ProcessId, Caption, ExecutablePath " +
"FROM Win32_Process";
string wmiScope = @"\\your_computer_name\root\cimv2";
ManagementObjectSearcher searcher = new ManagementObjectSearcher (wmiScope, query);
foreach (ManagementObject mo in searcher.Get ())
{
Console.WriteLine("Caption={0} CommandLine={1}",
mo["Caption"], mo["CommandLine"]);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With