使用VBscript检查计算机是否被锁定

dil*_*esh 5 vbscript

如何使用VBscript检查计算机是否已被锁定?我想在计算机被锁定后停止运行应用程序,并在解锁后再次运行它

Bon*_*ond 3

您可以尝试检查该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)