C # Implementation of the CMD command to implement the computer immediately/timed shutdown
This blog post focuses on a personal writing software that implements immediate and timed shutdown:
The main is through the call window under the Cmd.exe, and then execute the shutdown-related cmd command, the realization of the computer's immediate and scheduled shutdown, the implementation of the following. the first is to open the system's own cmd.exe:
<span style= "White-space:pre" ></span> process Process = new process (); Process. Startinfo.filename = "cmd.exe"; Process. Startinfo.useshellexecute = false; Process. Startinfo.redirectstandardinput = true; Process. Startinfo.redirectstandardoutput = true; Process. Startinfo.redirectstandarderror = true; Process. Startinfo.createnowindow = true; Process. Start ();
. After start, you can enter the cmd command to execute:
Process. Standardinput.writeline ("Shutdown-s-T 3"); Process. Standardinput.writeline ("Exit"); Shuttime = System.Int32.Parse (intime.text); Process. WaitForExit (); Process. Close ();
The following is the implementation of timed automatic shutdown, the same as the above implementation:
<span style= "White-space:pre" ></span> string time; Time = Intime.text; Process process = new process (); Process. Startinfo.filename = "cmd.exe"; Process. Startinfo.useshellexecute = false; Process. Startinfo.redirectstandardinput = true; Process. Startinfo.redirectstandardoutput = true; Process. Startinfo.redirectstandarderror = true; Process. Startinfo.createnowindow = true; Process. Start (); Process. Standardinput.writeline ("shutdown-s-T" + time); Process. Standardinput.writeline ("Exit"); Shuttime = System.Int32.Parse (intime.text); Process. WaitForExit (); Process. Close ();
Where time is the number of seconds to get the input.
Source resources: http://download.csdn.net/detail/laozhuxinlu/9512547
C # execute CMD command for computer shutdown