Retrieving the File Version
Microsoft® Windows® 2000 Scripting Guide
File versions that are incompatible or out-of-date can create considerable problems for system administrators. For example, a script that runs fine on Computer A, where version 2.0 of a particular DLL has been installed, might fail on Computer B, which has version 1.0 of that DLL installed.
These problems can be difficult to troubleshoot, because you are likely to get back an error saying that the object does not support a particular property or method. This is because the version of the object installed on Computer B does not support the new property or method. If you try to debug the script on Computer A, you will have difficulty finding the problem because the version of the object installed on Computer A does support the property or method in question.
The GetFileVersion method allows you to retrieve version information from a file. To use this method, a script must:
Create an instance of the FileSystemObject.
Call the GetFileVersion method, passing the path to the file as the sole parameter.
For example, the script in Listing 4.31 retrieves the file version for Scrrun.dll.
Listing 4.31 Retrieving File Versions
Set objFSO = CreateObject("Scripting.FileSystemObject") Wscript.Echo objFSO.GetFileVersion("c:\windows\system32\scrrun.dll")
When this script runs on a Windows 2000-based computer with WSH 5.6 installed, the message box shown in Figure 4.7 appears.
Figure 4.7 Version Number for Scrrun.dll
Version numbers are typically displayed in four parts, such as 126.96.36.19926, rather than a single number (such as version 1 or version 5). Version number 188.8.131.5226 contains the following parts:
5 - The major file part.
6 - The minor file part. The major and minor parts together represent the way a version is typically referred to. In conversation, you would likely refer to version 5.6 rather than version 184.108.40.20626.
0 - The build part. This is typically 0.
6626 - The private file part.
Not all files types support versioning. Executable files and DLLs typically support versioning; plain-text files, including scripts, typically do not.