c# - 如何关闭计算机?

标签 c# .net windows shutdown

如何使用 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/

相关文章:

c# - Action 过滤器 + AspNetRedisProvider

c# - 用于对文件进行分组的 Visual Studio 加载项

c# - C#VS2010不进入循环?

c# - 使用 Html Agility Pack,在循环中选择当前元素 (XPATH)

.net - 程序集未正确保存

windows - 我可以从 elisp 中读取 Windows 注册表吗?如何?

windows - go 命令在我的 Windows 机器上运行缓慢,在我的 Linux 上运行良好

C# - 子类中的自定义构造函数

c# - 如何将 pdf 转换为 .net 中的位图图像?

linux - Jenkins 到 git Windows master/Linux slave 的路径