2009-09-14 79 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