Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for savver.vbs

(view source code of savver.vbs as plain text)

  1. Option Explicit
  2. On Error Resume Next
  3.  
  4. Dim drive, fso, SAVDef, SAVDir1, SAVDir2, SAVDir3, SAVVer, strComputer, strMsg
  5. strMsg = vbCrLf
  6.  
  7. ' Parse command line
  8. If WScript.Arguments.Named.Count   > 0 Then Syntax
  9. If WScript.Arguments.UnNamed.Count > 1 Then Syntax
  10. If WScript.Arguments.UnNamed.Count = 1 Then
  11. 	If Ping( WScript.Arguments.UnNamed(0) ) Then
  12. 		strComputer = GetComputerName( WScript.Arguments.UnNamed(0) )
  13. 		drive       = "\\" & strComputer & "\C$"
  14. 	Else
  15. 		strMsg = strMsg & WScript.Arguments.UnNamed(0) & " is off-line" & vbCrLf & vbCrLf
  16. 		Syntax
  17. 	End If
  18. Else
  19. 	drive = "C:"
  20. 	strComputer = GetComputerName( "." )
  21. End If
  22.  
  23. ' Specify file locations
  24. SAVDir1 = drive & "\Program Files\SAV"
  25. SAVDir2 = drive & "\Program Files\Symantec AntiVirus"
  26. SAVDir3 = drive & "\Program Files\Common Files\Symantec Shared\VirusDefs"
  27.  
  28. ' Create file system object
  29. Set fso = CreateObject( "Scripting.FileSystemObject" )
  30.  
  31. ' Retrieve program file version info
  32. SAVVer  = fso.GetFileVersion( SAVDir1 & "\Rtvscan.exe" ) & fso.GetFileVersion( SAVDir2 & "\Rtvscan.exe" )
  33.  
  34. ' Retrieve definitions file version info
  35. SAVDef  = ReadINI( SAVDir3 & "\definfo.dat", "DefDates", "CurDefs" )
  36.  
  37. ' Display the result
  38. strMsg = strMsg _
  39.        & "Computer Name              : " & strComputer & vbCrLf _
  40.        & "Symantec AntiVirus version : " & SAVVer      & vbCrLf _
  41.        & "Virus definitions          : " & SAVDef      & vbCrLf
  42. WScript.Echo strMsg
  43.  
  44.  
  45. ' Get local computer name
  46. Function GetComputerName( strHost )
  47. 	Dim colItems, objItem, objWMIService
  48. 	Set objWMIService = GetObject( "winmgmts://" & strHost & "/root/cimv2" )
  49. 	Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
  50. 	For Each objItem in colItems
  51. 		GetComputerName = objItem.Name
  52. 	Next
  53. End Function
  54.  
  55.  
  56. ' Function to ping a specified host and returns boolean TRUE if it is contactable and FALSE if not
  57. Function Ping( strHost )
  58. '	On Error Resume Next
  59.  
  60. 	Dim objPing   : Set objPing   = Nothing ' The Win32_PingStatus WMI object
  61. 	Dim objStatus : Set objStatus = Nothing ' The result of the Win32_PingStatus WMI object
  62.  
  63. 	' Creates the ping object specifying the host to ping
  64. 	Set objPing = GetObject( "winmgmts:{impersonationLevel=impersonate}" ).ExecQuery( "SELECT * FROM Win32_PingStatus WHERE address = '" & strHost & "'" )
  65.  
  66. 	' Check the status of each ping response
  67. 	For Each objStatus In objPing
  68. 		' If the status code is Null or Not 0 then the ping failed
  69. 		If IsNull( objStatus.StatusCode ) Or objStatus.StatusCode <> 0 Then 
  70. 			' Set the function to return Boolean FALSE
  71. 			Ping = False
  72. 		Else
  73. 			' Set the function to return Boolean TRUE
  74. 			Ping = True
  75. 		End If
  76. 	Next
  77. End Function
  78.  
  79.  
  80. Function ReadINI( ini, section, key )
  81. 	'Initialize variables and constants
  82. 	Dim handle, keyfound, line, lineArray, linekey, lineval, objFso, sect, sectfound
  83. 	Const ForReading = 1
  84. 	sectfound = False
  85. 	sect      = "[" & Strip( section ) & "]"
  86. 	keyfound  = False
  87. 	ReadINI   = ""
  88.  
  89. 	'Open INI file in read-only mode
  90. 	Set objFso = CreateObject( "Scripting.FileSystemObject" )
  91. 	Set handle = objFso.OpenTextFile( ini, ForReading )
  92.  
  93. 	'Search the INI file for the specified key in the specified section
  94. 	Do While handle.AtEndOfStream <> True And keyfound = False
  95. 		line = Strip( handle.ReadLine )
  96. 		If Left( line, 1 ) = "[" Then
  97. 			If StrComp( line, sect, vbTextCompare ) = 0 Then
  98. 				sectfound = True
  99. 			Else
  100. 				sectfound = False
  101. 			End If
  102. 		Else
  103. 			If sectfound Then
  104. 				If InStr( 1, line, "=", vbTextCompare ) > 0 Then
  105. 					lineArray = Split( line, "=", 2, vbTextCompare )
  106. 					linekey = Strip( lineArray(0) )
  107. 					lineval = Strip( lineArray(1) )
  108. 					If StrComp( linekey, key, vbTextCompare ) = 0 Then
  109. 						ReadINI  = lineval
  110. 						keyfound = True
  111. 					End If
  112. 				End If
  113. 			End If
  114. 		End If
  115. 	Loop
  116.  
  117. 	'Close the file
  118. 	handle.close
  119. End Function
  120.  
  121.  
  122. 'Strip leading and trailing whitespace and quotes from a string
  123. Function Strip( mystring )
  124. 	Do While Left( mystring, 1 ) = " " Or Left( mystring, 1 ) = Chr(9)
  125. 		mystring = Mid( mystring, 2 )
  126. 	Loop
  127. 	Do While Right( mystring, 1 ) = " " Or Right( mystring, 1 ) = Chr(9)
  128. 		mystring = Mid( mystring, 1, Len( mystring ) - 1 )
  129. 	Loop
  130. 	If Left( mystring, 1 ) = Chr(34) Then
  131. 		mystring = Mid( mystring, 2 )
  132. 	End If
  133. 	If Right( mystring, 1 ) = Chr(34) Then
  134. 		mystring = Mid( mystring, 1, Len( mystring ) - 1 )
  135. 	End If
  136. 	Strip = mystring
  137. End Function
  138.  
  139.  
  140. Sub Syntax
  141. 	strMsg = vbCrLf _
  142. 	       & "SAVVer.vbs, Version 1.00" & vbCrLf _
  143. 	       & "Display Symantec AntiVirus program and definitions version" & vbCrLf & vbCrLf _
  144. 	       & "Usage:  [ CSCRIPT ]  SAVVER.VBS  [ host ]" & vbCrLf & vbCrLf _
  145. 	       & "Where:  " & Chr(34) & "host" & Chr(34) _
  146. 	       & "  is a remote computer's name or IP address" & vbCrLf _
  147. 	       & "                (default is the local computer)" & vbCrLf & vbCrLf _
  148. 	       & "Written by Rob van der Woude" & vbCrLf _
  149. 	       & "http://www.robvanderwoude.com"
  150. 	WScript.Echo strMsg
  151. 	WScript.Quit(1)
  152. End Sub
  153.  

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