'Script pulls last Windows update install info from registry 'Author: Bratislav STOJKOVIC 'E-mail: bratislav.stojkovic@gmail.com ' Script calculates curent date and "LastSuccessTime" from the registry. ' The same date you can find in Windows updates log If WScript.Arguments.Count<>2 Then WScript.Echo "Usage: cscript "& WScript.ScriptName& " /w: /c:" WScript.Quit End If set colNamedArguments = WScript.Arguments.Named updateTresholdWarning = Int(colNamedArguments.Item("w")) updateTresholdCritical = Int(colNamedArguments.Item("c")) Const intOK = 0 Const intWarning = 1 Const intCritical = 2 Const intUnknown = 3 Const HKEY_LOCAL_COMPUTER = &H80000002 strComputer = "localhost" strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Install" strEntryName = "LastSuccessTime" Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\default:StdRegProv") objReg.GetStringValue HKEY_LOCAL_COMPUTER, strKeyPath, strEntryName, strValue if IsNull(strValue) = -1 then Wscript.Echo "CRITICAL: Patches have NEVER been applied!" Wscript.Quit(intCritical) end if InstallDate = CDate(strValue) CurrentDate = CDate(Now) DD = DateDiff("d",InstallDate, CurrentDate) If DD > updateTresholdCritical Then Wscript.Echo "CRITICAL: Patches are not applied for the last " & DD & " days." Wscript.Quit(intCritical) ElseIf DD > updateTresholdWarning Then Wscript.Echo "WARNING: Patches are not applied for the last " & DD & " days." Wscript.Quit(intWarning) ElseIf DD < updateTresholdWarning Then Wscript.Echo "OK: Patches are not applied for the last " & DD & " days." Wscript.Quit(intOK) Else Wscript.Echo "UNKNOWN: State is unknown." Wscript.Quit(intUnknown ) End If