若要使用 StandardInput,您必须将 ProcessStartInfo.UseShellExecute 设置为 false,并且将 ProcessStartInfo.RedirectStandardInput 设置为 true。否则,写入 StandardInput 流时将引发异常。MSDN上的解释。
我没试验,你自己试一试。看看时候有帮助。

解决方案 »

  1.   

    private void button1_Click(object sender, EventArgs e) 
                { 
                    Process p = new Process(); 
                    p.StartInfo.FileName = "cmd.exe"; 
                    p.StartInfo.UseShellExecute = False;
                    p.StartInfo.RedirectStandardInput = True;
                    p.Start(); 
                    p.StandardInput.Write("shutdown -s -t 1"); 
                } 
      

  2.   

       Process p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.Start();
                p.StandardInput.WriteLine("shutdown -s -t 60");
                p.StandardInput.WriteLine("exit");