Windows 7 被锁定多久了?

How long has Windows 7 been locked?

有没有办法以编程方式(批处理文件、VBS)或通过第 3 方工具找出工作站已锁定多长时间(使用 Win+L 快捷方式)?脚本或第 3 方工具的输出应为 f.e。 60 分钟,如果工作站在 60 分钟后被锁定。

谢谢!

您可以使用此 VBScript 了解工作站是否被锁定..如果是,从何时被锁定。 此脚本将检查工作站锁定时创建的进程 LogonUI.exe 并获取该进程的创建日期。

Dim strReturn : strReturn = "."
Dim computer : computer = "."
If WScript.Arguments.Count = 1 Then
    computer = WScript.Arguments(0)
End If

Function WMIDateStringToDate(dtmStart)
    WMIDateStringToDate = CDate(Mid(dtmStart, 5, 2) & "/" & _
    Mid(dtmStart, 7, 2) & "/" & Left(dtmStart, 4) _
    & " " & Mid (dtmStart, 9, 2) & ":" & _
    Mid(dtmStart, 11, 2) & ":" & Mid(dtmStart, 13, 2))
End Function

Function IsWorkstationLocked( computer )
    Dim wmi : Set wmi = GetObject("winmgmts://" & computer & "/root/cimv2")
    Dim logonScreenCount
    Set logonScreenCount = wmi.ExecQuery ("SELECT * FROM Win32_Process WHERE Name = 'LogonUI.exe'")
    for each xxx in logonScreenCount
        StartTime = xxx.CreationDate
        strReturn = WMIDateStringToDate(StartTime)
        creationTime = xxx.CreationDate
        Next
    IsWorkstationLocked = (logonScreenCount.Count > 0)
End Function

If IsWorkstationLocked(computer) Then
    Wscript.Echo "locked since " & strReturn
Else
    Wscript.Echo "not locked"
End If

HTH!