TYT
TYT

Reputation: 23

Execute CMD Command by C# winform app?

I have sample code to run command but its not working ( just opens CMD ) without executing the command

string strCmdLine = 
     "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe " +
     "--load-extension=\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\toolbar-GC\"";

System.Diagnostics.Process.Start("CMD.exe", strCmdLine);
process1.Close();

where is problem ?

Upvotes: 2

Views: 13965

Answers (3)

Edi G.
Edi G.

Reputation: 2422

you need the parameter "/c"

string strCmdLine = 
 "/c C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe " +
 "--load-extension=\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\toolbar-GC\"";
System.Diagnostics.Process.Start("CMD.exe", strCmdLine);
process1.Close();

Upvotes: 0

codebased
codebased

Reputation: 7073

You don't need to use cmd.exe mate...

I guess this should do the job for you...

 string strCmdLine =
     "\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe \"";

            var parmaters = "google.com";
            System.Diagnostics.Process.Start(strCmdLine, parmaters);

Upvotes: 1

fahadash
fahadash

Reputation: 3281

You need to add a /C

Correct syntax for CMD.exe is

CMD.EXE /c command

string strCmdLine = 
     "/C C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe " +
     "--load-extension=\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\toolbar-GC\"";

System.Diagnostics.Process.Start("CMD.exe", strCmdLine);
process1.Close();

Upvotes: 7

Related Questions