aborting computer shutdown from windows service

余生长醉 提交于 2019-12-08 08:14:32

问题


Is it possible to abort computer shutdown from windows service?


回答1:


Yes. You can call shutdown /a using Process.Start

static void Main(string[] args)
{
    Process p = new Process();
    p.StartInfo.FileName = "shutdown";
    p.StartInfo.Arguments = "/r";
    p.Start();
    Thread.Sleep(5000);
    p.StartInfo.Arguments = "/a";
    p.Start();

}

The above code tells the computer to shutdown and restart, waits 5 seconds, then aborts it.




回答2:


AbortSystemShutdown

I've added a sample to my answer at the similar question here
How cancel shutdown from a windows service C#



来源:https://stackoverflow.com/questions/2729429/aborting-computer-shutdown-from-windows-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!