C # execute CMD command for computer shutdown

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.