C#执行DOS命令

以重启为例子:

Dos命令调用
    private void SystemOperate(string strParameter, string strOver)
        {
            System.Diagnostics.Process P = new System.Diagnostics.Process();
            P.StartInfo.FileName = "cmd.exe";
            //设置参数
            P.StartInfo.UseShellExecute = false;
            P.StartInfo.RedirectStandardInput = true;
            P.StartInfo.RedirectStandardOutput = true;
            P.StartInfo.CreateNoWindow = true;
            P.Start();

            //执行操作
            P.StandardInput.WriteLine(strParameter);
            P.StandardInput.WriteLine(strOver);
            P.Close();
        }

 

执行方法,传入重启命令:

MessageBox.Show("系统将重启");
SystemOperate("shutdown -r -t 0", "exit");

posted @ 2013-05-06 15:12  luosuo  阅读(233)  评论(0编辑  收藏  举报