(view source code of secstat.vbs as plain text)
Option ExplicitDim arrMonth, arrOSVerDim blnWUAUServ, blnWUOKDim dtmLastCheckDim intLC, intLD, intLI, intMonth, intTodayDim colItems, objItem, objReg, objWMISvcDim strComputer, strLastBoot, strLastCheck, strLastDownloadDim strLastInstall, strLB, strMsg, strRegKey, strWUMsgConst HKLM = &H80000002
arrMonth = Array( "Error", "January", "February", "March", "April", "May", "June", _
"July", "August", "September", "October", "November", "December" )
blnWUOK = True
With WScript.Arguments
If .Named.Count > 0 Then
If .Named.Exists( "?" ) And .Named.Count = 1 Then
Syntax "" Else Syntax "Invalid command line switches"End If
End If
If .Unnamed.Count > 1 Then
Syntax "Invalid number of command line arguments"End If
If .Unnamed.Count = 1 Then
strComputer = UCase( .Unnamed(0) )
ElsestrComputer = "."
End If
End With
' First check the OS version: XP (5.1) SP2 is the minimum requiredSet objWMISvc = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
Set colItems = objWMISvc.ExecQuery( "Select * from Win32_OperatingSystem", , 48 )
For Each objItem in colItems
' Read and store date and time of last bootstrLB = Left( objItem.LastBootUpTime, 14 )
strLastBoot = Left( strLB, 4 ) & "-" & Mid( strLB, 5, 2 ) & "-" _
& Mid( strLB, 7, 2 ) & " " & Mid( strLB, 9, 2 ) & ":" _
& Mid( strLB, 11, 2 ) & ":" & Mid( strLB, 13, 2 )
' Read and check Windows versionarrOSVer = Split( objItem.Version, "." )
If arrOSVer(0) < 5 Then
Syntax "This script requires Windows XP SP2 or later." & vbCrLf _
& " OS version detected: " & objItem.Caption & " SP " _
& objItem.ServicePackMajorVersion & "." _
& objItem.ServicePackMinorVersion & "."
End If
If arrOSVer(0) = 5 Then
If arrOSVer(1) = 0 Then
Syntax "This script requires Windows XP SP2 or later"End If
If objItem.ServicePackMajorVersion < 2 Then
Syntax "This script requires Windows XP SP2 or later"End If
End If
Next' Check if Windows Update service is runningSet colItems = objWMISvc.ExecQuery( "Select * From Win32_Service Where Name='wuauserv'", , 48 )
For Each objItem in colItems
If objItem.State = "Running" Then
blnWUAUServ = True
ElseblnWUAUServ = False
End If
Next' Custom error handling is required, since many properties to' be queried may be invalid for the installed security products'On Error Resume Next' Connect to the local or remote SecurityCenter through WMISet objWMISvc = GetObject( "winmgmts:{impersonationLevel=impersonate}!//" _
& strComputer & "/root/SecurityCenter" )
If Err Then
If strComputer = "." Then
Syntax "Could not connect to SecurityCenter" ElseSyntax "Could not connect to SecurityCenter on " & strComputer
End If
End If
' Query the installed AntiVirus productSet colItems = objWMISvc.ExecQuery( "SELECT * FROM AntiVirusProduct" )
If Err Then
Syntax "No AntiVirus product detected by WMI"End If
strMsg = vbCrLf & "AntiVirus:" & vbCrLf
If InStr( UCase( WScript.FullName ), "\CSCRIPT.EXE" ) Then strMsg = strMsg & "=========="
For Each objItem in colItems
With objItem 'WScript.Echo .companyName 'WScript.Echo .instanceGuidstrMsg = strMsg & vbCrLf & .displayName & ", Version " & .versionNumber
If .onAccessScanningEnabled Then
strMsg = strMsg & vbCrLf & "On-access scanning is enabled"
ElsestrMsg = strMsg & vbCrLf & "Warning: on-access scanning is disabled!"
End If
If .productUptoDate Then
strMsg = strMsg & vbCrLf & "Virus definitions are up-to-date"
ElsestrMsg = strMsg & vbCrLf & "Warning: virus definitions are NOT up-to-date!"
End If
End With
Next' Query the installed Firewall productSet colItems = objWMISvc.ExecQuery( "SELECT * FROM FirewallProduct" )
If Err Then
Syntax "No firewall detected by WMI"End If
strMsg = strMsg & vbCrLf & vbCrLf & "Firewall:" & vbCrLf
If InStr( UCase( WScript.FullName ), "\CSCRIPT.EXE" ) Then strMsg = strMsg & "========="
For Each objItem in colItems
With objItem 'WScript.Echo .companyName 'WScript.Echo .instanceGuidstrMsg = strMsg & vbCrLf & .displayName & ", Version " & .versionNumber
If .enabled Then
strMsg = strMsg & vbCrLf & "Firewall is enabled"
ElsestrMsg = strMsg & vbCrLf & "Warning: firewall is disabled!"
End If
End With
NextstrMsg = strMsg & vbCrLf & vbCrLf & "Windows Update:" & vbCrLf
If InStr( UCase( WScript.FullName ), "\CSCRIPT.EXE" ) Then strMsg = strMsg & "==============="
' Check if the Windows Update service is runningIf blnWUAUServ Then
strMsg = strMsg & vbCrLf & "Windows Update Service is active"
ElsestrMsg = strMsg & vbCrLf & "Warning: Windows Update Service NOT active!"
blnWUOK = False
End If
' Windows Update results are read from the registrySet objReg = GetObject( "winmgmts:{impersonationLevel=impersonate}!//" _
& strComputer & "/root/default:StdRegProv" )
strRegKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\"
' Read the time and date of the last successful downloadobjReg.GetStringValue HKLM, strRegKey & "Download", "LastSuccessTime", strLastDownload
strWUMsg = vbCrLf & "Last Download : " & strLastDownload
' Convert the time and date string to a long integerintLD = Left( strLastDownload, 10 )
intLD = Replace( IntLD, " ", "" )
intLD = Replace( intLD, "-", "" )
intLD = Replace( intLD, ":", "" )
intLD = CLng( intLD )
' Read the time and date of the last successful installobjReg.GetStringValue HKLM, strRegKey & "Install", "LastSuccessTime", strLastInstall
strWUMsg = strWUMsg & vbCrLf & "Last Install : " & strLastInstall
' Convert the time and date string to a long integerintLI = Left( strLastInstall, 10 )
intLI = Replace( intLI, " ", "" )
intLI = Replace( intLI, "-", "" )
intLI = Replace( intLI, ":", "" )
intLI = CLng( intLI )
' Insert the line with the last reboot date and timestrWUMsg = strWUMsg & vbCrLf & "Last Reboot : " & strLastBoot
' Read the time and date of the last successful check for new updatesobjReg.GetStringValue HKLM, strRegKey & "Detect", "LastSuccessTime", strLastCheck
strWUMsg = strWUMsg & vbCrLf & "Last Check : " & strLastCheck
' Convert the time and date string to a long integerintLC = Left( strLastCheck, 10 )
intLC = Replace( intLC, " ", "" )
intLC = Replace( intLC, "-", "" )
intLC = Replace( intLC, ":", "" )
intLC = CLng( intLC )
' Convert the long integer to a true dateintMonth = CInt( "1" & Mid( intLC, 5, 2 ) ) - 100
dtmLastCheck = CDate( Mid( intLC, 7, 2 ) & " " & arrMonth(intMonth) & " " & Left( intLC, 4 ) )
On Error Goto 0
' WU check includes the following requirements:' * Automatic Updates service must be running' * last successful download must be BEFORE last successful install' * last reboot must be AFTER last successful install' * last check must be no more than 7 days ago' If any of these tests fails, all intermediate results will be displayed,' if all tests are passed, a brief summary will be displayedIf intLD > intLI Then
strWUMsg = strWUMsg & vbCrLf & "Warning: last install was unsuccessful!"
blnWUOK = False
End If
If DateDiff( "d", dtmLastCheck, Now ) > 7 Then
strWUMsg = strWUMsg & vbCrLf & "Warning: the last check was " & DateDiff( "d", dtmLastCheck, Now ) & " days ago!"
blnWUOK = False
End If
If CLng( Left( strLB, 8 ) ) < intLI Then
strWUMsg = strWUMsg & vbCrLf & "Warning: a reboot is required!"
blnWUOK = False
End If
If blnWUOK Then strWUMsg = vbCrLf & "Windows Update seems to be functioning OK"
WScript.Echo strMsg & strWUMsg
Set objReg = Nothing
Set colItems = Nothing
Set objWMISvc = Nothing
Sub Syntax( myMsg )
If myMsg <> "" Then
strMsg = vbcrlf & "Error: " & myMsg & vbCrLf
ElsestrMsg = ""
End If
strMsg = strMsg & vbCrLf _
& "SecStat.vbs, Version 2.01 for Windows XP SP2 and later" _
& vbCrLf _& "Display a SecurityCenter and Windows Update status overview for any computer" _
& vbCrLf & vbCrLf _
& "Usage: SECSTAT.VBS [ computer ]" _
& vbCrLf & vbCrLf _
& "Where: ""computer"" is an optional remote computer name" _
& vbCrLf _& " (default is the local computer)" _
& vbCrLf & vbCrLf _
& "Inspired by an entry in Alejandro Campos Magencio's blog:" _
& vbCrLf _& "http://blogs.msdn.com/alejacma/archive/2008/05/12/how-" _
& vbCrLf _& "to-get-antivirus-information-with-wmi-vbscript.aspx." _
& vbCrLf & vbCrLf _
& "Use WBEMTEST to find all properties for specific products." _
& vbCrLf & vbCrLf _
& "Written by Rob van der Woude" _
& vbCrLf _& "http://www.robvanderwoude.com"
WScript.Echo strMsg
WScript.Quit 1
End Sub
page last modified: 2025-10-11; loaded in 0.0078 seconds