Option Explicit Dim arrReq, arrVer, blnArg, i, intReq, intRet, strVer intRet = 0 With WScript ' Either 1 unnamed argument or 1 named, not both If .Arguments.Named.Count * .Arguments.Unnamed.Count > 0 Then Syntax Select Case .Arguments.Unnamed.Count Case 0 ' Do nothing Case 1 ' Split the requested And actual versions into arrays arrReq = Split( .Arguments.Unnamed(0), "." ) arrVer = Split( .Version, "." ) ReDim Preserve arrVer(2) arrVer(2) = .BuildVersion ' Check if the requested version is numeric For i = 0 To UBound( arrReq ) If Not IsNumeric( arrReq(i) ) Then Syntax Next ' Compare the requested and actual versions intRet = 1 For i = 0 To UBound( arrReq ) If CLng( arrVer(i) ) > CLng( arrReq(i) ) Then intRet = 0 Exit For End If Next strVer = .Version & "." & .BuildVersion If strVer = .Arguments.Unnamed(0) Then intRet = 0 Case Else Syntax End Select Select Case .Arguments.Named.Count Case 0 ' No switch: display full version strVer = .Version & "." & .BuildVersion Case 1 blnArg = False If .Arguments.Named.Exists( "Major" ) Then strVer = Split( .Version, "." )(0) intReq = .Arguments.Named( "Major" ) intRet = Compare( strVer, intReq ) blnArg = True End If If .Arguments.Named.Exists( "Minor" ) Then strVer = Split( .Version, "." )(1) intReq = .Arguments.Named( "Minor" ) intRet = Compare( strVer, intReq ) blnArg = True End If If .Arguments.Named.Exists( "Build" ) Then strVer = .BuildVersion intReq = .Arguments.Named( "Build" ) intRet = Compare( strVer, intReq ) blnArg = True End If If Not blnArg Then Syntax Case Else Syntax End Select ' Display the version or part of it .Echo strVer End With ' Exit with the calculated return code WScript.Quit intRet Function Compare( myVer, myReq ) If MyReq = "" Then Compare = myVer Else If IsNumeric( myReq ) Then If myVer < myReq Then Compare = 1 Else Compare = 0 End If Else Syntax End If End If End Function Sub Syntax Dim strMsg strMsg = "WSHVer.vbs, Version 1.00" & vbCrLf _ & "Return WSH version number or part of it" & vbCrLf & vbCrLf _ & "Usage: CSCRIPT.EXE //NoLogo WSHVER.VBS [Req|((/Major|/Minor|/Build)[:Req])]" & vbCrLf & vbCrLf _ & "Where: /Major displays the major version number (e.g. 5)" & vbCrLf _ & " /Minor displays the minor version number (e.g. 7)" & vbCrLf _ & " /Build displays the build number (e.g. 16535)" & vbCrLf _ & " Req is the minimum required value; if specified, the return code" & vbCrLf _ & " will be 0 if the actual version is equal to or greater than" & vbCrLf _ & " Req, or 1 if it is less; if not specified, the return code" & vbCrLf _ & " will be equal to the version number part (e.g. 7 for /Minor)" & vbCrLf & vbCrLf _ & "Examples (assuming actual version 5.7.16535) Display Return code" & vbCrLf _ & "============================================ ======= ===========" & vbCrLf _ & "CSCRIPT.EXE //NoLogo WSHVER.VBS 5.6 5.7.16535 0 (requirement met)" & vbCrLf _ & "CSCRIPT.EXE //NoLogo WSHVER.VBS /Major:6 5 1 (not met)" & vbCrLf _ & "CSCRIPT.EXE //NoLogo WSHVER.VBS /Minor:6 7 0 (met)" & vbCrLf _ & "CSCRIPT.EXE //NoLogo WSHVER.VBS /Minor 7 7 (minor version)" & vbCrLf & vbCrLf _ & "Written by Rob van der Woude" & vbCrLf _ & "http://www.robvanderwoude.com" WScript.Echo strMsg WScript.Quit 1 End Sub