(view source code of secstat2.vbs as plain text)
Option ExplicitDim arrOSVerDim blnDomainMember, blnWFwEnabled, blnWUAUServ, blnWUOKDim dtmLastCheckDim intLC, intLD, intLI, intMonth, intToday, lngProductStateDim colItems, objFSO, objItem, objReg, objWMIService, wshShellDim strComputer, strLastBoot, strLastCheck, strLastDownloadDim strLastInstall, strLB, strMsg, strProductName, strProductPathDim strRegKey, strProductVersion, strTmpMsg, strWUMsgConst HKLM = &H80000002
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
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
Set wshShell = CreateObject( "WScript.Shell" )
' First check the OS version: Vista (6.0) is the minimum requiredSet objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
Set colItems = objWMIService.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 Vista or later." & vbCrLf _
& vbtab & "OS version detected: " & objItem.Caption & " SP " _
& objItem.ServicePackMajorVersion & "." _
& objItem.ServicePackMinorVersion & "."
End If
If arrOSVer(0) < 6 Then
Syntax "SecStat2.vbs requires Windows Vista or later." & vbCrLf _
& vbtab & "OS version detected: " & objItem.Caption & " SP " _
& objItem.ServicePackMajorVersion & "." _
& objItem.ServicePackMinorVersion & vbCrLf _
& vbTab & "For Windows XP SP2 or SP3 use SecStat.vbs instead of SecStat2.vbs"
End If
Next' Check if the computer is a domain memberSet colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem" )
For Each objItem in colItems
blnDomainMember = CBool( objItem.PartOfDomain )
Next' Check if Windows Update service is runningSet colItems = objWMIService.ExecQuery( "Select * From Win32_Service Where Name='wuauserv'", , 48 )
For Each objItem in colItems
blnWUAUServ = ( objItem.State = "Running" )
Next' Custom error handling is required, since many properties to be queried may be invalid for the installed security productsOn Error Resume Next
' Connect to the local or remote SecurityCenter through WMISet objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/SecurityCenter2" )
If Err Then
If strComputer = "." Then
Syntax "Could not connect to SecurityCenter2" ElseSyntax "Could not connect to SecurityCenter2 on " & strComputer
End If
End If
' Query the installed AntiVirus productstrMsg = vbCrLf & "AntiVirus:" & vbCrLf
If InStr( UCase( WScript.FullName ), "\CSCRIPT.EXE" ) Then strMsg = strMsg & "=========="
Set colItems = objWMIService.ExecQuery( "SELECT * FROM AntiVirusProduct" )
If Err Then
strMsg = strMsg & vbCrLf & "No AntiVirus product detected by WMI"
ElseIf colItems.Count = 0 Then
strMsg = strMsg & vbCrLf & "No AntiVirus product detected by WMI"
End If
For Each objItem in colItems
With objItemstrProductName = .displayName
strProductPath = wshShell.ExpandEnvironmentStrings( .pathToSignedProductExe )
strProductVersion = objFSO.GetFileVersion( strProductPath )
lngProductState = CLng( .productState )
strMsg = strMsg & vbCrLf & strProductName & ", Version " & strProductVersion
strTmpMsg = "Warning: unable to determine on-access scanning status!"
If ( lngProductState And &H001000& ) = &H001000& Then
strTmpMsg = "On-access scanning is enabled"
ElsestrTmpMsg = "Warning: on-access scanning is disabled!"
End If
strMsg = strMsg & vbCrLf & strTmpMsg
strTmpMsg = "Warning: unable to determine whether virus definitions are up-to-date or not!"
If ( lngProductState And &H000010& ) = 0 Then
strTmpMsg = "Virus definitions are up-to-date"
ElsestrTmpMsg = "Warning: virus definitions are NOT up-to-date!"
End If
strMsg = strMsg & vbCrLf & strTmpMsg
End With
strMsg = strMsg & vbCrLf
Next' Query the installed AntiSpyware productstrMsg = strMsg & vbCrLf & "AntiSpyware:" & vbCrLf
If InStr( UCase( WScript.FullName ), "\CSCRIPT.EXE" ) Then strMsg = strMsg & "============"
Set colItems = objWMIService.ExecQuery( "SELECT * FROM AntiSpywareProduct" )
If Err Then
strMsg = strMsg & vbCrLf & "No AntiSpyware product detected by WMI"
ElseIf colItems.Count = 0 Then
strMsg = strMsg & vbCrLf & "No AntiSpyware product detected by WMI"
End If
For Each objItem in colItems
With objItemstrProductName = .displayName
strProductPath = wshShell.ExpandEnvironmentStrings( .pathToSignedProductExe )
strProductVersion = objFSO.GetFileVersion( strProductPath )
lngProductState = CLng( .productState )
strMsg = strMsg & vbCrLf & strProductName & ", Version " & strProductVersion
strTmpMsg = "Warning: unable to determine on-access scanning status!"
If ( lngProductState And &H001000& ) = &H001000& Then
strTmpMsg = "On-access scanning is enabled"
ElsestrTmpMsg = "Warning: on-access scanning is disabled!"
End If
strMsg = strMsg & vbCrLf & strTmpMsg
strTmpMsg = "Warning: unable to determine whether malware definitions are up-to-date or not!"
If ( lngProductState And &H000010& ) = 0 Then
strTmpMsg = "Malware definitions are up-to-date"
ElsestrTmpMsg = "Warning: malware definitions are NOT up-to-date!"
End If
strMsg = strMsg & vbCrLf & strTmpMsg
End With
strMsg = strMsg & vbCrLf
Next' Query the installed Firewall productstrMsg = strMsg & vbCrLf & "Firewall:" & vbCrLf
If InStr( UCase( WScript.FullName ), "\CSCRIPT.EXE" ) Then strMsg = strMsg & "========="
Set colItems = objWMIService.ExecQuery( "SELECT * FROM FirewallProduct" )
If Err Then
strMsg = strMsg & vbCrLf & "No third party firewall detected by WMI"
ElseIf colItems.Count = 0 Then
strMsg = strMsg & vbCrLf & "No third party firewall detected by WMI"
End If
For Each objItem in colItems
With objItemstrProductName = .displayName
strProductVersion = objFSO.GetFileVersion( .pathToSignedProductExe )
lngProductState = CLng( .productState )
strMsg = strMsg & vbCrLf & strProductName & ", Version " & strProductVersion
strTmpMsg = "Warning: unable to determine whether third party firewall is enabled or not!"
If ( lngProductState And &H010000& ) = &H001000& Then
strTmpMsg = "Third party firewall is enabled"
ElsestrTmpMsg = "Warning: third party firewall is disabled!"
End If
strMsg = strMsg & vbCrLf & strTmpMsg
End With
strMsg = strMsg & vbCrLf
NextstrRegKey = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SharedAccess\Parameters\FirewallPolicy\"
If blnDomainMember Then
strRegKey = strregkey & "DomainProfile"
ElsestrRegKey = strregkey & "StandardProfile"
End If
strRegKey = strregkey & "\EnableFirewall"
blnWFwEnabled = ( wshShell.RegRead( strRegKey ) = 1 )
If Err Then
strTmpMsg = "Warning: unable to determine whether Windows Firewall is enabled or not!"
ElseIf blnWFwEnabled Then
strTmpMsg = "Windows Firewall is enabled"
ElsestrTmpMsg = "Warning: Windows Firewall is disabled!"
End If
End If
strMsg = strMsg & vbCrLf & strTmpMsg
strMsg = 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 )
dtmLastCheck = CDate( intLC )
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
' Forget the intermediate results if everything turns out OKIf blnWUOK Then strWUMsg = vbCrLf & "Windows Update reports: everything OK"
WScript.Echo strMsg & strWUMsg
Set objFSO = Nothing
Set objReg = Nothing
Set colItems = Nothing
Set objWMIService = Nothing
Set wshShell = Nothing
Sub Syntax( myMsg )
If myMsg <> "" Then
strMsg = vbcrlf & "Error:" & vbTab & myMsg & vbCrLf
ElsestrMsg = ""
End If
strMsg = strMsg & vbCrLf _
& "SecStat2.vbs, Version 1.01 for Windows Vista and later" _
& vbCrLf _& "Display a SecurityCenter2 and Windows Update status overview for any computer" _
& vbCrLf & vbCrLf _
& "Usage: " & vbTab & "SECSTAT.VBS" & vbTab & "[ computer ]" _
& vbCrLf & vbCrLf _
& "Where: " & vbTab & """computer""" & vbTab & "is an optional remote computer name" _
& vbCrLf _& " " & vbTab & vbTab & vbTab & "(default is the local computer)" _
& vbCrLf & vbCrLf _
& "Credits:" & vbTab & "Inspired by a blog entry on neophob.com:" _
& vbCrLf _& " " & vbTab & "http://neophob.com/2010/03/#post-154" _
& vbCrLf & vbCrLf _
& "Use WBEMTEST.EXE (or WMIGEN.HTA) 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.0125 seconds