防止 Windows 7 关机 [英] Prevent Windows 7 Shutdown

查看:27
本文介绍了防止 Windows 7 关机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 shutdown -a 会中止 Windows 关机,但我需要知道是否有任何可以检查的地方,以查看是否正在进行关机.

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")

推荐答案

为了防止发生 Windows 关机,您可以对 WM_QUERYENDSESSION 消息(不知道您是否可以使用 Python 的 win32 API 轻松做到这一点,但在 C 中很简单).这可能不会阻止应用程序关闭,因为 Windows 将 WM_ENDSESSION 发送给那些对查询消息回答 TRUE 的应用程序.

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.

我猜您更愿意使用shutdown.exe"来防止定时关机.我确定该程序使用 InitiateSystemShutdown显示关闭对话框,但没有拦截该调用的资源(至少我没有找到或知道允许这样操作的 Windows 功能).

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).

这篇关于防止 Windows 7 关机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆