Option Explicit Dim arrReq, arrVer, blnArg, i, intReq, intRet, strVer intRet = 0 With WScript ' Read the current version arrVer = Split( .Version, "." ) ReDim Preserve arrVer(2) arrVer(2) = .BuildVersion strVer = .Version & "." & .BuildVersion ' 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), "." ) ' 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 = 0 For i = 0 To Min( 2, UBound( arrReq ) ) If CLng( arrVer(i) ) > CLng( arrReq(i) ) Then Exit For End If If CLng( arrVer(i) ) < CLng( arrReq(i) ) Then intRet = 1 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: just display full version Case 1 blnArg = False If .Arguments.Named.Exists( "Major" ) Then strVer = arrVer(0) intRet = Compare( strVer, .Arguments.Named( "Major" ) ) blnArg = True End If If .Arguments.Named.Exists( "Minor" ) Then strVer = arrVer(1) intRet = Compare( strVer, .Arguments.Named( "Minor" ) ) blnArg = True End If If .Arguments.Named.Exists( "Build" ) Then strVer = arrVer(2) intRet = Compare( strVer, .Arguments.Named( "Build" ) ) 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 Function Min( num1, num2 ) If Not IsNumeric( num1 ) Then Syntax If Not IsNumeric( num2 ) Then Syntax If num1 < num2 Then Min = num1 Else Min = num2 End If End Function Sub Syntax Dim strMsg, strVer strVer = arrVer(0) & "." & arrVer(1) & "." & arrVer(2) strMsg = "WSHVer.vbs, Version 1.10" _ & vbCrLf _ & "Return WSH version number or part of it" _ & vbCrLf & vbCrLf _ & "Usage: WSHVER.VBS [ minreq | (/Major|/Minor|/Build)[:minreq] ]" _ & vbCrLf & vbCrLf _ & "Where: /Major displays the major version number (e.g. " & arrver(0) & ")" _ & vbCrLf _ & " /Minor displays the minor version number (e.g. " & arrver(1) & ")" _ & vbCrLf _ & " /Build displays the build number (e.g. " & arrver(2) & ")" _ & vbCrLf _ & " minreq 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. " & arrver(1) & " for /Minor)" _ & vbCrLf & vbCrLf _ & "Examples Display Return code" _ & vbCrLf _ & "==================== ========= ===========================" _ & vbCrLf _ & "WSHVER.VBS " & arrver(0) & "." & arrVer(1) - 1 & " " & strVer & " 0 (requirement met)" _ & vbCrLf _ & "WSHVER.VBS " & arrVer(0) & "." & arrVer(1) - 1 & "." & arrVer(2) + 10000 & " " & strver & " 0 (requirement met)" _ & vbCrLf _ & "WSHVER.VBS " & arrver(0) + 1 & " " & strver & " 1 (requirement not met)" _ & vbCrLf _ & "WSHVER.VBS /Major " & arrver(0) & " " & arrver(0) & " (major version)" _ & vbCrLf _ & "WSHVER.VBS /Minor:" & arrver(1) - 1 & " " & arrver(1) & " 0 (requirement met)" _ & vbCrLf _ & "WSHVER.VBS /Minor " & arrver(1) & " " & arrver(1) & " (minor version)" _ & vbCrLf _ & "WSHVER.VBS /Build " & arrver(2) & " " & arrver(2) & " (build version)" _ & vbCrLf & vbCrLf _ & "Written by Rob van der Woude" _ & vbCrLf _ & "http://www.robvanderwoude.com" WScript.Echo strMsg WScript.Quit 1 End Sub