Export (0) Print
Expand All

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:

  1. Create an instance of the FileSystemObject.

  2. 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

  
1
2


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

sas_scr_07s

Version numbers are typically displayed in four parts, such as 5.6.0.6626, rather than a single number (such as version 1 or version 5). Version number 5.6.0.6626 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 5.6.0.6626.

  • 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.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft