您可以尝试检查该logonui.exe进程是否存在。如果找到它,则计算机已锁定或未登录。
Function IsLocked(strComputer)
With GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
IsLocked = .ExecQuery("select * from Win32_Process where Name='logonui.exe'").Count > 0
End With
End Function
Run Code Online (Sandbox Code Playgroud)
要测试本地计算机,请传递 PC 名称或句点。例如:
If IsLocked(".") Then MsgBox "Local computer is locked."
Run Code Online (Sandbox Code Playgroud)