Instant power off programmatically?

被刻印的时光 ゝ 提交于 2019-12-06 13:26:29

This can be accomplished on *nix systems by using the system requests feature. Generally this is disabled for security reasons, but you can enable it with root privileges and request power off to the system immediately as follows:

echo 1 > /proc/sys/kernel/sysrq-trigger ;
echo o > /proc/sysrq-trigger

where the letter 'o' means "power off". Other functions are available. https://en.wikipedia.org/wiki/Magic_SysRq_key

The ExitWindowsEx function is the standard shutdown, and even with EWX_FORCE it still closes all programs, services etc... it just does not ask / wait for them to close.

So what's the solution? Use NtShutdownSystem.

That function does the actual shutdown, by flushing the caches, registry etc and then calling the BIOS to power down the machine.

Look here for an usage example:
http://www.codeproject.com/Articles/34194/Performing-emergency-shutdowns

you can use ExitWindowsEx with EWX_POWEROFF and EWX_FORCE flags set...

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