Windows 下用 API 控制系统的锁定/注销/重启/关机

在 Windows 下,有个函数叫 ExitWindowsEx ,可以用来控制系统的锁定、登出、重启和关机。主要就是通过给该函数传入不同的值来执行不同的操作。掌握该函数的使用就能更好的控制你的计算机。

ExitWindowsEx函数原型

传入值和对于功能

EWX_HYBRID_SHUTDOWN(0x00400000)
从 Windows8 开始的混合关机模式。
Beginning with Windows 8: You can prepare the system for a faster startup by combining the EWX_HYBRID_SHUTDOWN flag with the EWX_SHUTDOWN flag.

EWX_LOGOFF(0)
关闭所有进程并注销。
Shuts down all processes running in the logon session of the process that called the ExitWindowsEx function. Then it logs the user off.

EWX_POWEROFF(0x00000008)
关闭系统并切断电源,系统支持电源关闭功能。
Shuts down the system and turns off the power. The system must support the power-off feature.

EWX_REBOOT(0x00000002)
关闭系统并重启。
Shuts down the system and then restarts the system.

EWX_RESTARTAPPS(0x00000040)
关闭系统并重启,被注册到重启项的应用将一起重启。
Shuts down the system and then restarts it, as well as any applications that have been registered for restart using the RegisterApplicationRestart function.

EWX_SHUTDOWN(0x00000001)
关闭系统并在安全状态下关闭电源。
Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped.

示例1:关机

示例2:强制关机

如无注明,均为原创。转载请注明: 转载自MITGAI`S THINKING
本文链接地址: Windows 下用 API 控制系统的锁定/注销/重启/关机

知识共享许可协议本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。

如果本文对您生活或工作产生了积极影响,那我非常高兴。
如果您愿意为文章的内容或想法提供支持,欢迎点击下边的捐赠按钮,资助作者创作更多高价值高品质的内容。
支付宝捐赠
anyShare分享到:

发表评论