防止 Windows 7 关机
我知道 shutdown -a 会中止 Windows 关闭,但我需要知道是否有任何地方可以检查关闭是否正在进行中。
理想情况下,我想要一个像这样的小程序:
import os
while True:
shuttingDown = <shutdown variable to check>
if shuttingDown:
os.system("shutdown.exe -a")
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")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了防止 Windows 关闭时发生,您可以对 WM_QUERYENDSESSION 消息(不知道是否可以使用 Python 的 win32 API 轻松做到这一点,但在 C 中很简单)。这可能不会阻止应用程序关闭,因为 Windows 会将 WM_ENDSESSION 发送给那些对查询消息回答 TRUE 的应用程序。
我想您宁愿使用“shutdown.exe”来防止定时关闭。我确信该程序使用 InitiateSystemShutdown 来显示关闭对话框,但没有关于拦截该调用的资源(至少我没有找到或不知道允许此类操作的 Windows 功能)。
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).