gpt4 book ai didi

python - 在 Python 3 中,如何判断 Windows 是否被锁定?

转载 作者:可可西里 更新时间:2023-11-01 14:44:52 27 4
gpt4 key购买 nike

如何检查 Windows 操作系统工作站是否被锁定? (例如 Win+L 或在 Ctrl+Alt+Del 之后选择锁定选项。)

我想要像 ctypes.windll.user32.isWorkstationLocked() 这样的东西。

最佳答案

这段代码今天在四台不同的 Windows 7 和 10 机器上对我有效,尝试类似的东西:

import ctypes
import time
user32 = ctypes.windll.User32
time.sleep(5)
#
#print(user32.GetForegroundWindow())
#
if (user32.GetForegroundWindow() % 10 == 0): print('Locked')
# 10553666 - return code for unlocked workstation1
# 0 - return code for locked workstation1
#
# 132782 - return code for unlocked workstation2
# 67370 - return code for locked workstation2
#
# 3216806 - return code for unlocked workstation3
# 1901390 - return code for locked workstation3
#
# 197944 - return code for unlocked workstation4
# 0 - return code for locked workstation4
#
else: print('Unlocked')

编辑:另外,这个今天有效:

import subprocess
import time
time.sleep(5)
process_name='LogonUI.exe'
callall='TASKLIST'
outputall=subprocess.check_output(callall)
outputstringall=str(outputall)
if process_name in outputstringall:
print("Locked.")
else:
print("Unlocked.")

关于python - 在 Python 3 中,如何判断 Windows 是否被锁定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34514644/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com