Introduction to Checking Version NumbersThere are occasions when you need to investigate the VBScript
version number. For example, if you have old clients with version 2.x., VBScript commands may not work. To give a specific example you may want a script to pause, in which case you could use
WScript.Sleep. The problem is that this .Sleep property was only added in WSH version 5.1. If you are sure all your clients are XP, then no problem, but if the scripts are going to run on
Windows 9x machines you may wish to check the version with a simple script.
The first bonus of checking version numbers is that investigation reveals just how many
components are involved in a VBscript, for instance, Windows Scripting
Host (WSH) and also VBScript itself. Topics for Checking Version Numbers
VBScripts need a shell called Windows Scripting Host (WSH). Examples 1 and 2 are designed to extract the version information about WSH. (In Example 3 we switch to the VBScript itself.) PrerequisitesThis is a script that will
execute equally well on a Windows server or an XP machine.
Instructions for Checking WSH Version
- Copy and paste the example script below into notepad or a VBScript editor.
- Save the file with a .vbs extension, for example, WSH.vbs
- Double click WSH.vbs and read the version in the message box.
Sample VBScript to Check the WSH Version
' WSH.vbs ' Sample VBScript to check WSH Version ' Author Guy Thomas http://computerperformance.co.uk/ ' Version 1.3 - September 2005 '
-------------------------------------------------------------------- On Error Resume Next WScript.Echo "WSH Version: " & WScript.Version WScript.Quit
VBScript Tutorial - Learning PointsNote 1: I am expecting the script to return a WScript version of 5.6 Note 2: Here we have a mixture of literals: "WSH
Version: " and variables: WScript.Version. Paying attention to detail pays off. In this instance, notice how the space before the closing quotes makes the output easier to understand.
Note 3: Time and time ampersand (&) is your friend in joining VBScript components. I have to confess that I am often concentrating so hard on the more difficult commands that I forget the
ampersand. When I make this sin of omission, WSH brings me up sharply with a message: Code 800A0401 - Expected end of statement.
|