Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass multiple arguments in processStartInfo?

I want to run some cmd command from c#code. I followed some blogs and tutorial and got the answer, but I am in little bit confused i.e how should I pass multiple arguments?

I use follow code:

System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; startInfo.FileName = "cmd.exe"; startInfo.Arguments =  ... 

What will be the startInfo.Arguments value for the following command line code?

  • makecert -sk server -sky exchange -pe -n CN=localhost -ir LocalMachine -is Root -ic MyCA.cer -sr LocalMachine -ss My MyAdHocTestCert.cer

  • netsh http add sslcert ipport=127.0.0.1:8085 certhash=0000000000003ed9cd0c315bbb6dc1c08da5e6 appid={00112233-4455-6677-8899-AABBCCDDEEFF} clientcertnegotiation=enable

like image 250
Amit Pal Avatar asked Feb 25 '13 07:02

Amit Pal


People also ask

How to pass multiple arguments to ProcessStartInfo in c#?

Just use "&&" in your command line.

What is C# ProcessStartInfo?

ProcessStartInfo(String, String) Initializes a new instance of the ProcessStartInfo class, specifies an application file name with which to start the process, and specifies a set of command-line arguments to pass to the application.


2 Answers

It is purely a string:

startInfo.Arguments = "-sk server -sky exchange -pe -n CN=localhost -ir LocalMachine -is Root -ic MyCA.cer -sr LocalMachine -ss My MyAdHocTestCert.cer" 

Of course, when arguments contain whitespaces you'll have to escape them using \" \", like:

"... -ss \"My MyAdHocTestCert.cer\"" 

See MSDN for this.

like image 128
bash.d Avatar answered Sep 20 '22 08:09

bash.d


System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; startInfo.FileName = "cmd.exe"; startInfo.Arguments = @"/c -sk server -sky exchange -pe -n CN=localhost -ir LocalMachine -is Root -ic MyCA.cer -sr LocalMachine -ss My MyAdHocTestCert.cer" 

use /c as a cmd argument to close cmd.exe once its finish processing your commands

like image 24
Zaid Amir Avatar answered Sep 21 '22 08:09

Zaid Amir