Prevent Windows 7 Shutdown

筅森魡賤 提交于 2019-12-07 08:07:49

问题


I know that shutdown -a will abort a Windows shutdown, but I need to know if there is anything any where I can check for to see if a shutdown is in progress.

Ideally, I'd like a small program like this:

 import os

 while True:
    shuttingDown = <shutdown variable to check>
    if shuttingDown:
         os.system("shutdown.exe -a")

回答1:


For preventing a Windows shutdown when it is happening, you can react to the WM_QUERYENDSESSION message (don't know if you can do that easily with Python's win32 API but it's simple in C). This might not prevent applications from closing because Windows sends WM_ENDSESSION to those that answer TRUE to the query message.

I guess you rather want to prevent a timed shutdown using "shutdown.exe". I'm sure that program uses InitiateSystemShutdown to show the shutdown dialog, but there are no resources on intercepting that call (at least I didn't find any or know of a Windows feature that allows such a thing).



来源:https://stackoverflow.com/questions/2358929/prevent-windows-7-shutdown

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