2009-09-14 76 views
2

我想编写一个脚本,它可以递归扫描目录中的DLL并生成所有版本号的报告。使用脚本检测DLL版本号

如何使用脚本检测DLL的版本号? VBScript解决方案是首选,除非有更好的方法。

+0

如果你想在VB6中做到这一点。看一下这个。为我工作100%: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=4976&lngWId=1 – Koekiebox 2009-09-14 15:32:17

+0

您可以看看PowerShell。 – TrueWill 2009-09-14 17:27:45

+0

增加了'vbscript'标签。 – Helen 2009-09-14 18:36:21

回答

4

可以使用FileSystemObject对象来访问文件系统及其GetFileVersion方法来获取文件版本信息。

你问一个VBScript例子,所以在这里你是:

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 

用法:

> cscript //nologo script-file.vbsfolder >out-file

例如为:

> cscript //nologo dll-list.vbs C:\Dir > dll-list.txt

输出示例:

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

编辑我觉得this是我引用

这是我用的,我道歉剧本,但我不从那里召回源。 (所以,读者,如果这是从您的脚本开始的,请继续前进)它使用可直接获取版本的FileSystemObject。

@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