如何使用 C# 关闭计算机?
最佳答案
一个简单的方法:使用 Process.Start 来运行 shutdown.exe。
shutdown /s /t 0
编程方式:P/Invoke 调用ExitWindowsEx
这将是 P/Invoke 签名:
[DllImport("aygshell.dll", SetLastError="true")]
private static extern bool ExitWindowsEx(uint dwFlags, uint dwReserved);
在任何情况下,运行代码的用户都需要关闭系统权限(通常不是问题,但要记住这一点很重要)。
关于c# - 如何关闭计算机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/665385/