代码之家  ›  专栏  ›  技术社区  ›  Rickson

Windows 7已锁定多长时间?

  •  1
  • Rickson  · 技术社区  · 10 年前

    是否有方法通过程序(批处理文件,VBS)或通过第三方工具(使用Win+L快捷方式)来确定工作站已锁定多长时间?如果工作站在60分钟后被锁定,则脚本或第三方工具的输出应为例如60分钟。

    谢谢

    1 回复  |  直到 10 年前
        1
  •  1
  •   Rickson    10 年前

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

    嗯!