Process proc = new Process(); proc.StartInfo.FileName = "cmd.exe"; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.RedirectStandardInput = true; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.CreateNoWindow = true; proc.Start(); string commandLine; if (isCancel) commandLine = @"shutdown /a"; else commandLine = @"shutdown /f /s /t " + interval.ToString(); proc.StandardInput.WriteLine(commandLine);
以执行关机为例。