在 Python 3 中,如何判断 Windows 是否已锁定? [英] In Python 3, how can I tell if Windows is locked?

查看:34
本文介绍了在 Python 3 中,如何判断 Windows 是否已锁定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I check whether a Windows OS workstation is locked? (e.g. Win+L or choosing the lock option after Ctrl+Alt+Del.)

我想要类似 ctypes.windll.user32.isWorkstationLocked() 的东西.

I want something like ctypes.windll.user32.isWorkstationLocked().

推荐答案

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

This code worked today for me on four different Windows 7 and 10 machines, try something similar:

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 3 中,如何判断 Windows 是否已锁定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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