用c#代码设置电脑关机和重启
重新启动代码如下
// An highlighted block
try
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
p.StandardInput.WriteLine("shutdown -r -t 1");
p.StandardInput.WriteLine("exit");
}
catch
{
}
备注:这段代码里面的命令是适用于windows系统的,如果是设置关机,只需要把上面代码里面的“shutdown -r -t 1”改成“shutdown -s -t 1”