Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for secstat.kix

(view source code of secstat.kix as plain text)

  1. $RC = SetOption( "EXPLICIT", "ON" )
  2.  
  3. Dim $arrCmdLine, $arrOSVer, $colItems, $Computer, $False, $Msg, $objItem, $objWMISvc, $True
  4.  
  5. $False =  0
  6. $True  = -1
  7.  
  8. ; Check if a computer name was passed on the command line
  9. ; (assuming the last and only argument is the computer name)
  10. $arrCmdLine = GetCommandLine( 1 )
  11. If InStr( $arrCmdLine[Ubound( $arrCmdLine )], @SCRIPTNAME )
  12. 	$Computer = "."
  13. Else
  14. 	$Computer = $arrCmdLine[Ubound( $arrCmdLine )]
  15. EndIf
  16.  
  17. ; Error message in case the OS version check fails
  18. $Msg = "This script requires Windows XP SP2 or later.@CRLF"
  19. $Msg = $Msg + "       OS version detected: " + $objItem.Caption
  20. $Msg = $Msg + " SP " + $objItem.ServicePackMajorVersion
  21. $Msg = $Msg + "." + $objItem.ServicePackMinorVersion + "."
  22.  
  23. ; First check the OS version: XP (5.1) SP2 is the minimum required,
  24. ; since the SecurityCenter was introduced in Windows XP SP2
  25. $objWMISvc = GetObject( "winmgmts://$Computer/root/CIMV2" )
  26. $colItems  = $objWMISvc.ExecQuery( "SELECT * FROM Win32_OperatingSystem" )
  27. For Each $objItem In $colItems
  28. 	$arrOSVer = Split( $objItem.Version, "." )
  29. 	If $arrOSVer[0] < 5 ; Windows NT 4 or before
  30. 		Syntax( $Msg )
  31. 		Quit 1
  32. 	EndIf
  33. 	If $arrOSVer[0] = 5 ; Windows 2000 or before
  34. 		If $arrOSVer[1] = 0
  35. 			Syntax( $Msg )
  36. 			Quit 1
  37. 		EndIf
  38. 		If $objItem.ServicePackMajorVersion < 2 ; Windows XP SP1 or before
  39. 			Syntax( $Msg )
  40. 			Quit 1
  41. 		EndIf
  42. 	EndIf
  43. Next
  44.  
  45. ; Error message in case connecting to the SecurityCenter fails
  46. $Msg = "Could not connect to SecurityCenter"
  47.  
  48. ; Connect to the local or remote SecurityCenter through WMI
  49. $objWMISvc = GetObject( "winmgmts:{impersonationLevel=impersonate}!//$Computer/root/SecurityCenter" )
  50. If @ERROR <> 0
  51. 	If $Computer = "."
  52. 		Syntax( $Msg )
  53. 		Quit 1
  54. 	Else
  55. 		Syntax( "$Msg  on $Computer" )
  56. 		Quit 1
  57. 	EndIf
  58. EndIf
  59.  
  60. ; Query the installed AntiVirus product
  61. $colItems = $objWMISvc.ExecQuery( "SELECT * FROM AntiVirusProduct", "WQL", 48 )
  62. If @ERROR <> 0
  63. 	Syntax( "No AntiVirus product detected by WMI" )
  64. 	Quit 1
  65. EndIf
  66.  
  67. ; Format the returned results
  68. $Msg = "@CRLF" + "AntiVirus:@CRLF==========@CRLF"
  69.  
  70. For Each $objItem In $colItems
  71. 	$Msg = $Msg + $objItem.displayName + ", Version " + $objItem.versionNumber + "@CRLF"
  72. 	If $objItem.onAccessScanningEnabled = $True
  73. 		$Msg = $Msg + "On-access scanning is enabled@CRLF"
  74. 	Else
  75. 		$Msg = $Msg + "Warning: on-access scanning is disabled!@CRLF"
  76. 	EndIf
  77. 	If $objItem.productUptoDate = $True
  78. 		$Msg = $Msg + "Virus definitions are up-to-date@CRLF"
  79. 	Else
  80. 		$Msg = $Msg + "Warning: virus definitions are NOT up-to-date!@CRLF"
  81. 	EndIf
  82. Next
  83.  
  84. ; Query the installed Firewall product
  85. $colItems = $objWMISvc.ExecQuery( "SELECT * FROM FirewallProduct", "WQL", 48 )
  86. If @ERROR <> 0
  87. 	Syntax( "No firewall detected by WMI" )
  88. 	Quit 1
  89. EndIf
  90.  
  91. ; Format the returned results
  92. $Msg = "$Msg@CRLF" + "Firewall:@CRLF=========@CRLF"
  93.  
  94. For Each $objItem In $colItems
  95. 	$Msg = $Msg + $objItem.displayName + ", Version " + $objItem.versionNumber + "@CRLF"
  96. 	If $objItem.enabled = $True
  97. 		$Msg = $Msg + "Firewall is enabled@CRLF"
  98. 	Else
  99. 		$Msg = $Msg + "Warning: firewall is disabled!@CRLF"
  100. 	EndIf
  101. Next
  102.  
  103. ; Display the results
  104. "$Msg"
  105.  
  106. $colItems  = Nothing
  107. $objWMISvc = Nothing
  108.  
  109. Quit 0
  110.  
  111.  
  112. Function Syntax( $myMsg )
  113. 	Dim $S
  114. 	CLS
  115. 	$S = "@CRLF"
  116. 	If $myMsg <> ""
  117. 		$S = $S + "Error: $myMsg@CRLF@CRLF"
  118. 	EndIf
  119. 	$S = $S + "SecStat.kix,  Version 1.01 for Windows XP SP2 and later@CRLF"
  120. 	$S = $S + "Display a SecurityCenter status overview For any computer@CRLF@CRLF"
  121. 	$S = $S + "Usage:  KIX32.EXE  SECSTAT.KIX  [ computer ]@CRLF@CRLF"
  122. 	$S = $S + "Where:  " + Chr(34) + "computer" + Chr(34)
  123. 	$S = $S + "   is an optional remote computer name@CRLF"
  124. 	$S = $S + "                     (default is the local computer)@CRLF@CRLF"
  125. 	$S = $S + "Inspired by an entry in Alejandro Campos Magencio's blog:@CRLF"
  126. 	$S = $S + "http://blogs.msdn.com/alejacma/archive/2008/05/12/how-@CRLF"
  127. 	$S = $S + "to-get-antivirus-information-with-wmi-vbscript.aspx.@CRLF@CRLF"
  128. 	$S = $S + "Use WBEMTEST to find all properties for specific products.@CRLF@CRLF"
  129. 	$S = $S + "Written by Rob van der Woude@CRLF"
  130. 	$S = $S + "http://www.robvanderwoude.com"
  131. 	$Syntax = $S
  132. EndFunction
  133.  

page last modified: 2024-04-16; loaded in 0.0228 seconds