Windows 7被锁定了多长时间?

时间:2015-03-09 16:56:51

标签: batch-file vbscript windows-7

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

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以使用此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!