I need to pass more than one command line argument via c# for a process called handle.exe: http://www.google.com.mt/search?sourceid=chrome&ie=UTF-8&q=handle.exe
First, I need to run the executable file via ADMINISTRATOR permissions. This post has helped me achieve just that: programatically run cmd.exe as adminstrator in vista, c#
But then comes the next problem of calling the actual line arguments such as "-p explore"
How can I specify the command line arguments together, or maybe consecutively?
Current code is as follows:
Process p = new Process();
ProcessStartInfo processStartInfo = new ProcessStartInfo("filePath");
processStartInfo.CreateNoWindow = true;
processStartInfo.UseShellExecute = false;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardInput = true;
processStartInfo.Verb = "runas";
processStartInfo.Arguments = "/env /user:" + "Administrator" + " cmd";
p.StartInfo = processStartInfo;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Console.WriteLine(output);
Thanks
I know for sure that there are two command-line arguments in C -- argc and argv[] , but while taking an online test, I figured out that there are 3 command line arguments in C.
Yes, we can give arguments in the main() function. Command line arguments in C are specified after the name of the program in the system's command line, and these argument values are passed on to your program during program execution. The argc and argv are the two arguments that can pass to main function.
Explanation: 2 arguments are needed to be passed to main() function while using command line arguments. The first one represents a number of strings in the argument list and the second list represents the list of string arguments. 3.
I believe the answer you are looking for is right out of the Runas command documentation.
runas /user:[email protected] "notepad my_file.txt"
It appears that the last argument to the runas command is the command that is being run along with any arguments. The key is to use quotes to group the actual command executable with it's arguments so that the values are not seen as separate arguments to the runas command but instead is issued as a single command on it's own.
So in your example you might want to do the following.
processStartInfo.Arguments = "/env /user:" + "Administrator" + " \"cmd -p explore\"";
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