Hey, Scripting Guy! How can I determine the version number of an executable file?
— TW
Hey, TW. Well, that depends. If the file is located on the local computer, the easiest way is to use the FileSystemObject. Have a burning desire to know which version of Regedit.exe is installed on your computer? All it takes is two lines of code:
Set objFSO = CreateObject("Scripting.FileSystemObject") Wscript.Echo objFSO.GetFileVersion("c:\windows\regedit.exe")
As you can see, this is about as simple a script as you’ll ever write. In line 1, we create an instance of the FileSystemObject; in line 2, we use the GetFileVersion method to return the version number of C:\Windows\Regedit.exe. That’s all there is to it.
OK, we know: some of you are thinking, “Sure, that works fine if the file in question is located on the local computer. But what if that file is located on a remote computer? After all, the FileSystemObject is designed to work locally, not remotely. What do we do then?”
Relax; if the file is located remotely, you can use WMI and the CIM_DataFile class to get back this same information. Here’s a script that reports the version of Regedit,exe installed on the remote computer atl-ws-01:
strComputer = "atl-ws-01" Set objWMIService = GetObject _ ("winmgmts:\\" & strComputer & "\root\cimv2") Set colFiles = objWMIService.ExecQuery _ ("SELECT * FROM CIM_DataFile WHERE Name = 'c:\\windows\\regedit.exe'") For Each objFile in colFiles Wscript.Echo objFile.Version Next
Again, pretty straightforward, with one exception: notice that you have to use two slashes (\\) any time you include a path name in a WQL query. As a result, we end up looking for C:\\Windows\\Regedit.exe rather than C:\Windows\Regedit.exe. Other than that it’s a regular old WMI script, the kind you’ve written many times before
0 comments