Detecting a DLL version number using a script
Question
I would like to write a script that can recursively scan the DLLs in a directory and generate a report of all of their version numbers.
How can I detect the version number of a DLL using a script? VBScript solutions are preferred, unless there is a better way.
Solution
You can use the FileSystemObject
object to access the file system and its GetFileVersion
method to obtain the file version information.
You asked for a VBScript example, so here you are:
Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")
PrintDLLVersions oFSO.GetFolder(WScript.Arguments.Item(0))
Sub PrintDLLVersions(Folder)
Dim oFile, oSubFolder
' Scan the DLLs in the Folder
For Each oFile In Folder.Files
If UCase(oFSO.GetExtensionName(oFile)) = "DLL" Then
WScript.Echo oFile.Path & vbTab & oFSO.GetFileVersion(oFile)
End If
Next
' Scan the Folder's subfolders
For Each oSubFolder In Folder.SubFolders
PrintDLLVersions oSubFolder
Next
End Sub
Usage:
> cscript //nologo script-file.vbs folder > out-file
e.g.:
> cscript //nologo dll-list.vbs C:\Dir > dll-list.txt
Sample output:
C:\Dir\foo.dll 1.0.0.1 C:\Dir\bar.dll 1.1.0.0 C:\Dir\SubDir\foobar.dll 4.2.0.0 ...
OTHER TIPS
EDIT I think this is the source I referenced
This is the script that I use, I apologize, but I don't recall from where. (So,reader, if this started as your script please step forward) It uses the FileSystemObject which can get version directly.
@echo off
setlocal
set vbs="%temp%\filever.vbs"
set file=%1
echo Set oFSO = CreateObject("Scripting.FileSystemObject") >%vbs%
echo WScript.Echo oFSO.GetFileVersion(WScript.Arguments.Item(0)) >>%vbs%
for /f "tokens=*" %%a in (
'cscript.exe //Nologo %vbs% %file%') do set filever=%%a
del %vbs%
echo Full file version of %file% is: %filever%
for /f "tokens=2 delims=. " %%a in ("%filever%") do set secondparam=%%a
set splevel=%secondparam:~0,1%
echo SP level is: %splevel%
endlocal
pause