我用过this excellent method锁定 Windows 计算机;那部分工作正常。然而,我想做的是检测计算机何时解锁,然后继续执行我的程序。我在网上做了相当多的研究来找到一种方法来做到这一点,但我还没有看到任何方法让 python 检测计算机状态的变化(即当计算机再次登录或解锁时)。 Python 是否可以检测 Windows 计算机何时解锁或登录?注意我正在使用 python 2.7.6 和 Windows 7。谢谢
最佳答案
我在 http://timgolden.me.uk/python/win32_how_do_i/see_if_my_workstation_is_locked.html 中找到了一个脚本
import time
import ctypes
user32 = ctypes.windll.User32
OpenDesktop = user32.OpenDesktopA
SwitchDesktop = user32.SwitchDesktop
DESKTOP_SWITCHDESKTOP = 0x0100
user32.LockWorkStation ()
#
# Slight pause to overcome what appears to
# be a grace period during which a switch
# *will* succeed.
#
time.sleep (1.0)
while 1:
hDesktop = OpenDesktop ("default", 0, False, DESKTOP_SWITCHDESKTOP)
result = SwitchDesktop (hDesktop)
if result:
print "Unlocked"
break
else:
print time.asctime (), "still locked"
time.sleep (2)
关于python - 检测计算机何时解锁 Windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26599462/