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

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

有帮助吗?

解决方案

您可以使用 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.vbs folder > out-file

e.g:

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

其他提示

编辑我认为这个是我引用的来源

这是我使用的脚本,我道歉,但我不记得从哪里来。 (所以,读者,如果这是从你的脚本开始请向前迈进)它使用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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top