简体   繁体   中英

C# command line in code

I'm trying to run hidden console with this command "winsat formal" in my C# code, but it is giving an error in "Process.Start()". Here is my code:

string command = "winsat formal";

Process process = new Process();
process.StartInfo.FileName = command;
process.Start();

You need to pass the parameters as follows.

Process process = new Process();

process.StartInfo.FileName = "winsat" ;

//in here you add as many parameters as needed
process.StartInfo.Arguments = "formal" ; 

process.Start();

UPDATE 1

If you go to "cmd" command line and type "winsat formal" does it work ? If not you need to do one of these

  • Add the path to the "winsat" executable to the PATH environment variable
  • Or specify the folder where the executable is located like this

process.StartInfo.WorkingDirectory = "c:\\your\\path\\toWinSat\\executable\\" ;

If it still does not work please let me know

UPDATE 2

//Have you tried proving a full path to the executable ?

process.StartInfo.FileName = "C:\windows\system32\winsat.exe" 

Also there are other posible ways of calling the Start method that can be usefull

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM