例如使用Windows自代的shutdown命令关机:
string command = "shutdown -f -s -t 0";
Process newProcess = new Process();
newProcess.StartInfo.FileName = "cmd.exe";
newProcess.StartInfo.UseShellExecute = false;
newProcess.StartInfo.CreateNoWindow = true;
newProcess.StartInfo.RedirectStandardOutput = true;
newProcess.StartInfo.RedirectStandardInput = true;
newProcess.StartInfo.RedirectStandardError = true;
try
{
newProcess.Start();
newProcess.StandardInput.WriteLine(command);
newProcess.StandardInput.Close();
output = newProcess.StandardOutput.ReadToEnd();
newProcess.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}