Instant power off programmatically?

只愿长相守 提交于 2019-12-10 10:32:45

问题


Under Windows XP Pro in a networked environment such that Ctrl+Alt+Del gives you the Windows Security prompt, if you hold Ctrl and click shutdown it triggers an Emergency Shutdown.

This appears to turn off the system so fast it doesn't even what for processes to finish, i.e. almost as if you just pulled the power/long-held the power button.

I am wondering by what process Windows achieves such a quick shutdown - is it instructing the BIOS directly via ACPI/APM to power down the system? If so, how could this be achieved programatically in any language?


回答1:


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




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/15636059/instant-power-off-programmatically

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