代码之家  ›  专栏  ›  技术社区  ›  sourcenouveau

使用脚本检测DLL版本号

  •  2
  • sourcenouveau  · 技术社区  · 15 年前

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

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

    2 回复  |  直到 15 年前
        1
  •  4
  •   Helen    15 年前

    你可以使用 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

    例如。:

    > 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
  •  2
  •   cmsjr    15 年前

    编辑 我想 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