Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for wininver.vbs

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

  1. Option Explicit
  2.  
  3. Dim arrCur, arrReq
  4. Dim i, intChk, intRC, intReq
  5. Dim objFSO, wshShell
  6. Dim strMsiExec, strVersion, strWindir
  7.  
  8. intRC = 0
  9.  
  10. ' Check the command line argument(s)
  11. If WScript.Arguments.Named.Count   > 0 Then Syntax
  12. If WScript.Arguments.Unnamed.Count > 1 Then Syntax
  13. If WScript.Arguments.Unnamed.Count = 1 Then
  14. 	arrReq = Split( WScript.Arguments.Unnamed(0), "." )
  15. 	For i = 0 To UBound( arrReq )
  16. 		If Not IsNumeric( arrReq(i) )     Then Syntax
  17. 		If CInt( arrReq(i) ) <> CDbl( arrReq(i) ) Then Syntax
  18. 	Next
  19. End If
  20.  
  21. ' Create the required objects
  22. Set objFSO   = CreateObject( "Scripting.FileSystemObject" )
  23. Set wshShell = CreateObject( "WScript.Shell" )
  24.  
  25. ' Get the path to the Windows Installer executable (MSIEXEC.EXE)
  26. strWindir  = wshShell.ExpandEnvironmentStrings( "%WinDir%" )
  27. strMsiExec = objFSO.BuildPath( strWindir, "system32\msiexec.exe" )
  28.  
  29. If objFSO.FileExists( strMsiExec ) Then
  30. 	' Get MSIEXEC.EXE's file version
  31. 	strVersion = objFSO.GetFileVersion( strMsiExec )
  32. 	WScript.Echo strVersion
  33. 	' Compare it to a specified minimum, if applicable
  34. 	If WScript.Arguments.Unnamed.Count = 1 Then
  35. 		arrCur = Split( strVersion, "." )
  36. 		intChk = UBound( arrCur )
  37. 		If intChk > UBound( arrReq ) Then intReq = UBound( arrReq )
  38. 		For i = 0 To intChk
  39. 			If CInt( arrCur(i) ) <  CInt( arrReq(i) ) Then intRC = 1
  40. 			If CInt( arrCur(i) ) <> CInt( arrReq(i) ) Then Exit For
  41. 		Next
  42. 	End If
  43. Else
  44. 	intRC = 1
  45. 	Syntax
  46. End If
  47.  
  48. WScript.Quit intRC
  49.  
  50.  
  51. Sub Syntax
  52. 	Dim strMsg
  53. 	strMsg = vbCrLf _
  54. 	       & "WinInVer.vbs,  Version 1.01" _
  55. 	       & vbCrLf _
  56. 	       & "Check the installed Windows Installer version, and optionally compare it" _
  57. 	       & vbCrLf _
  58. 	       & "to a specified minimum required version number" _
  59. 	       & vbCrLf & vbCrLf _
  60. 	       & "Usage:  CSCRIPT.EXE  //NoLogo  wininver.vbs  [ min_req ]" _
  61. 	       & vbCrLf & vbCrLf _
  62. 	       & "Where:  ""min_req""  is the minimum required version, e.g. ""3.1.4000.1823""" _
  63. 	       & vbCrLf & vbCrLf _
  64. 	       & "Return codes:" _
  65. 	       & vbCrLf _
  66. 	       & "     0: installed version is equal to or newer than the specified minimum," _
  67. 	       & vbCrLf _
  68. 	       & "        or no minimum version was specified" _
  69. 	       & vbCrLf _
  70. 	       & "     1: installed version is older than the specified minimum" _
  71. 	       & vbCrLf _
  72. 	       & "     2: invalid command line argument(s)" _
  73. 	       & vbCrLf _
  74. 	       & "     3: Windows Installer executable wasn't found" _
  75. 	       & vbCrLf & vbCrLf _
  76. 	       & "Written by Rob van der Woude" _
  77. 	       & vbCrLf _
  78. 	       & "http://www.robvanderwoude.com"
  79. 	WScript.Echo strMsg
  80. 	WScript.Quit intRC + 2
  81. End Sub
  82.  

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