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

如何设置现有的.exe,.dll的版本信息?

  •  92
  • Carl  · 技术社区  · 16 年前

    作为构建过程的一部分,我需要为所有编译的二进制文件设置版本信息。有些二进制文件已经有版本信息(在编译时添加),而有些则没有。

    • 公司名称
    • 版权声明
    • 品名
    • 文件版本
    • 产品版本

    我该怎么做?

    14 回复  |  直到 11 年前
        1
  •  55
  •   UweBaemayr    10 年前

    虽然它不是批处理过程,但Visual Studio也可以添加/编辑文件资源。

        2
  •  33
  •   Danny Beckett    11 年前

    首先,创建一个名为 Resources.rc 这样地:

    VS_VERSION_INFO VERSIONINFO
        FILEVERSION    1,0,0,0
        PRODUCTVERSION 1,0,0,0
    {
        BLOCK "StringFileInfo"
        {
            BLOCK "040904b0"
            {
                VALUE "CompanyName",        "ACME Inc.\0"
                VALUE "FileDescription",    "MyProg\0"
                VALUE "FileVersion",        "1.0.0.0\0"
                VALUE "LegalCopyright",     "© 2013 ACME Inc. All Rights Reserved\0"
                VALUE "OriginalFilename",   "MyProg.exe\0"
                VALUE "ProductName",        "My Program\0"
                VALUE "ProductVersion",     "1.0.0.0\0"
            }
        }
        BLOCK "VarFileInfo"
        {
            VALUE "Translation", 0x409, 1200
        }
    }
    

    GoRC 把它编译成 .res 文件使用:

    GoRC /fo Resources.res Resources.rc
    

    (见下面我的评论 GoRC.exe )

    Resource Hacker 在CLI模式中将其添加到现有的 .exe

    ResHacker -add MyProg.exe, MyProg.exe, Resources.res,,,
    

    就这样!

        3
  •  22
  •   Simon Sobisch    8 年前

    或者你可以看看免费软件 StampVer 对于Win32 exe/dll文件。
    它只会改变文件和产品的版本,如果他们已经有一个版本资源。如果不存在版本资源,则无法添加版本资源。

        4
  •  18
  •   a paid nerd    9 年前

    是相对较新的,从命令行运行良好: https://github.com/atom/rcedit

    $ rcedit "path-to-exe-or-dll" --set-version-string "Comments" "This is an exe"
    $ rcedit "path-to-exe-or-dll" --set-file-version "10.7"
    $ rcedit "path-to-exe-or-dll" --set-product-version "10.7"
    

    还有一个 NPM module Grunt task 以防你用呼噜声。

        5
  •  14
  •   CharlesB Craig McQueen    12 年前

    像这样的怎么样?

    verpatch /va foodll.dll %VERSION% %FILEDESCR% %COMPINFO% %PRODINFO% %BUILDINFO%
    

    可用 here with full sources

        6
  •  10
  •   Wolf    9 年前

    有这个工具 ChangeVersion [一]

    • 命令行界面
    • 支持.EXE、.DLL和.RES文件
    • 添加/更改/删除版本密钥字符串
    • 调整文件标志(调试、特殊、专用等)
    • 更新项目文件(.bdsproj |.bpr |.bpk |.dproj)
    • 使用带有配置的ini文件
    • Windows Vista支持(需要提升)
    • 易于集成到连续构建环境中


    [一] 链接已断开。似乎有镜像版本在 download.cnet.com .

        7
  •  9
  •   Sensei James    7 年前

    我不需要额外的工具。我刚刚将以下文件添加到我的Win32应用程序项目中。

    一个头文件,它定义了一些常量,我们可以在资源文件甚至程序代码中重用。我们只需要维护一个文件。

    ----[版本.h]----

    #ifndef VERSION_H
    #define VERSION_H
    
    #define VER_FILEVERSION             0,3,0,0
    #define VER_FILEVERSION_STR         "0.3.0.0\0"
    
    #define VER_PRODUCTVERSION          0,3,0,0
    #define VER_PRODUCTVERSION_STR      "0.3.0.0\0"
    
    #define VER_COMPANYNAME_STR         "IPanera"
    #define VER_FILEDESCRIPTION_STR     "Localiza archivos duplicados"
    #define VER_INTERNALNAME_STR        "MyProject"
    #define VER_LEGALCOPYRIGHT_STR      "Copyright 2016 ipanera@gmail.com"
    #define VER_LEGALTRADEMARKS1_STR    "All Rights Reserved"
    #define VER_LEGALTRADEMARKS2_STR    VER_LEGALTRADEMARKS1_STR
    #define VER_ORIGINALFILENAME_STR    "MyProject.exe"
    #define VER_PRODUCTNAME_STR         "My project"
    
    #define VER_COMPANYDOMAIN_STR       "www.myurl.com"
    
    #endif // VERSION_H
    

    ----[我的项目版本.rc]----

    #include <windows.h>
    #include "version.h"
    
    VS_VERSION_INFO VERSIONINFO
    FILEVERSION     VER_FILEVERSION
    PRODUCTVERSION  VER_PRODUCTVERSION
    BEGIN
        BLOCK "StringFileInfo"
        BEGIN
            BLOCK "040904E4"
            BEGIN
                VALUE "CompanyName",        VER_COMPANYNAME_STR
                VALUE "FileDescription",    VER_FILEDESCRIPTION_STR
                VALUE "FileVersion",        VER_FILEVERSION_STR
                VALUE "InternalName",       VER_INTERNALNAME_STR
                VALUE "LegalCopyright",     VER_LEGALCOPYRIGHT_STR
                VALUE "LegalTrademarks1",   VER_LEGALTRADEMARKS1_STR
                VALUE "LegalTrademarks2",   VER_LEGALTRADEMARKS2_STR
                VALUE "OriginalFilename",   VER_ORIGINALFILENAME_STR
                VALUE "ProductName",        VER_PRODUCTNAME_STR
                VALUE "ProductVersion",     VER_PRODUCTVERSION_STR
            END
        END
    
        BLOCK "VarFileInfo"
        BEGIN
            VALUE "Translation", 0x409, 1252
        END
    END
    
        8
  •  8
  •   techvice    10 年前
        9
  •  4
  •   CristiFati    5 年前

    我下载了最新版本( 5.1.7条 [AngusJ]: Resource Hacker . 所有需要的信息都可以在该页面上找到(命令行选项、脚本…)。在下面的演练中,我将对两个可执行文件(lab rats)进行操作,这些文件(出于明显的原因)是我在 水煤浆 :

    • ResourceHacker.exe
    • cmake.exe :随机可执行文件,没有 版本信息 3.6.3版 安装在我的机器上)

    在继续之前,我想提一下 资源黑客 ,下面的复制/粘贴片段可能会产生一些混乱。

    一。安装程序

    这更像是一个初步的步骤,熟悉环境,表明没有什么时髦的业务在进行。。。

    e:\Work\Dev\StackOverflow\q000284258> sopr.bat
    *** Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ***
    
    [prompt]> dir
     Volume in drive E is Work
     Volume Serial Number is 3655-6FED
    
     Directory of e:\Work\Dev\StackOverflow\q000284258
    
    2019-01-28  20:09    <DIR>          .
    2019-01-28  20:09    <DIR>          ..
    2016-11-03  09:17         5,413,376 cmake.exe
    2019-01-03  02:06         5,479,424 ResourceHacker.exe
    2019-01-28  20:30               496 ResourceHacker.ini
                   3 File(s)     10,893,296 bytes
                   2 Dir(s)  103,723,261,952 bytes free
    
    [prompt]> set PATH=%PATH%;c:\Install\x64\CMake\CMake\3.6.3\bin
    
    [prompt]> .\cmake --help >nul 2>&1
    
    [prompt]> echo %errorlevel%
    0
    
    [prompt]> .\ResourceHacker.exe -help
    
    [prompt]>
    
    ==================================
    Resource Hacker Command Line Help:
    ==================================
    
    -help             : displays these abbreviated help instructions.
    -help commandline : displays help for single commandline instructions
    -help script      : displays help for script file instructions.
    
    
    
    
    [prompt]> echo %errorlevel%
    0
    

    细节

    Img0-Initial

    2。资源

    资源文件是包含资源的文本文件。资源(简化)具有:

    • 姓名

    有关详细信息,请检查 [MS.Docs]: About Resource Files . 有许多工具(在现有的答案中提到)有助于资源文件编辑,例如:

    • 启动新项目时创建默认项目
    • 可以手动创建这样的文件
    • 但是,既然是关于 资源编译器

      • 它能够从现有的可执行文件中提取资源。
      • 它嵌入了资源(如上图所示)

      -action extract )

    .exe文件 ( .dll文件 ,…)一定是 编译的 体育课 格式。再说一次,有很多工具可以实现这一点,但正如你可能猜到的,我将坚持 资源编译器 ( -action compile ).

    [prompt]> :: Extract the resources into a file
    [prompt]> .\ResourceHacker.exe -open .\ResourceHacker.exe -save .\sample.rc -action extract -mask VersionInfo,, -log con
    
    [prompt]>
    
    [28 Jan 2019, 20:58:03]
    
    Current Directory:
    e:\Work\Dev\StackOverflow\q000284258
    
    Commandline:
    .\ResourceHacker.exe  -open .\ResourceHacker.exe -save .\sample.rc -action extract -mask VersionInfo,, -log con
    
    Open    : e:\Work\Dev\StackOverflow\q000284258\ResourceHacker.exe
    Save    : e:\Work\Dev\StackOverflow\q000284258\sample.rc
    
    
    Success!
    
    [prompt]> :: Modify the resource file and set our own values
    [prompt]>
    [prompt]> :: Compile the resource file
    [prompt]> .\ResourceHacker.exe -open .\sample.rc -save .\sample.res -action compile -log con
    
    [prompt]>
    
    [28 Jan 2019, 20:59:51]
    
    Current Directory:
    e:\Work\Dev\StackOverflow\q000284258
    
    Commandline:
    .\ResourceHacker.exe  -open .\sample.rc -save .\sample.res -action compile -log con
    
    Open    : e:\Work\Dev\StackOverflow\q000284258\sample.rc
    Save    : e:\Work\Dev\StackOverflow\q000284258\sample.res
    
    Compiling: e:\Work\Dev\StackOverflow\q000284258\sample.rc
    Success!
    
    [prompt]> dir /b
    cmake.exe
    ResourceHacker.exe
    ResourceHacker.ini
    sample.rc
    sample.res
    

    :

    1 VERSIONINFO
    FILEVERSION 3,1,4,1592
    PRODUCTVERSION 2,7,1,8
    FILEOS 0x4
    FILETYPE 0x1
    {
    BLOCK "StringFileInfo"
    {
        BLOCK "040904E4"
        {
            VALUE "CompanyName", "Cristi Fati\0"
            VALUE "FileDescription", "20190128 - SO q000284258 demo\0"
            VALUE "FileVersion", "3.1.4.1592\0"
            VALUE "ProductName", "Colonel Panic\0"
            VALUE "InternalName", "100\0"
            VALUE "LegalCopyright", "(c) Cristi Fati 1999-2999\0"
            VALUE "OriginalFilename", "ResHack\0"
            VALUE "ProductVersion", "2.7.1.8\0"
        }
    }
    
    BLOCK "VarFileInfo"
    {
        VALUE "Translation", 0x0409 0x04E4  
    }
    }
    

    三。嵌入

    这也将由 资源编译器 -action addoverwrite ). 自从 .exe文件 s已经被复制了我要在适当的地方编辑他们的资源。

    [prompt]> .\ResourceHacker.exe -open .\cmake.exe -save .\cmake.exe -res .\sample.res -action addoverwrite -mask VersionInfo,, -log con
    
    [prompt]>
    
    [28 Jan 2019, 21:17:19]
    
    Current Directory:
    e:\Work\Dev\StackOverflow\q000284258
    
    Commandline:
    .\ResourceHacker.exe  -open .\cmake.exe -save .\cmake.exe -res .\sample.res -action addoverwrite -mask VersionInfo,, -log con
    
    Open    : e:\Work\Dev\StackOverflow\q000284258\cmake.exe
    Save    : e:\Work\Dev\StackOverflow\q000284258\cmake.exe
    Resource: e:\Work\Dev\StackOverflow\q000284258\sample.res
    
      Added: VERSIONINFO,1,1033
    
    Success!
    
    [prompt]> copy ResourceHacker.exe ResourceHackerTemp.exe
            1 file(s) copied.
    
    [prompt]> .\ResourceHackerTemp.exe -open .\ResourceHacker.exe -save .\ResourceHacker.exe -res .\sample.res -action addoverwrite -mask VersionInfo,, -log con
    
    [prompt]>
    
    [28 Jan 2019, 21:19:29]
    
    Current Directory:
    e:\Work\Dev\StackOverflow\q000284258
    
    Commandline:
    .\ResourceHackerTemp.exe  -open .\ResourceHacker.exe -save .\ResourceHacker.exe -res .\sample.res -action addoverwrite -mask VersionInfo,, -log con
    
    Open    : e:\Work\Dev\StackOverflow\q000284258\ResourceHacker.exe
    Save    : e:\Work\Dev\StackOverflow\q000284258\ResourceHacker.exe
    Resource: e:\Work\Dev\StackOverflow\q000284258\sample.res
    
      Modified: VERSIONINFO,1,1033
    
    Success!
    
    [prompt]> del /f /q ResourceHackerTemp.*
    
    [prompt]> dir
     Volume in drive E is Work
     Volume Serial Number is 3655-6FED
    
     Directory of e:\Work\Dev\StackOverflow\q000284258
    
    2019-01-28  21:20    <DIR>          .
    2019-01-28  21:20    <DIR>          ..
    2016-11-03  09:17         5,414,400 cmake.exe
    2019-01-03  02:06         5,479,424 ResourceHacker.exe
    2019-01-28  21:17               551 ResourceHacker.ini
    2019-01-28  20:05             1,156 sample.rc
    2019-01-28  20:59               792 sample.res
                   5 File(s)     10,896,323 bytes
                   2 Dir(s)  103,723,253,760 bytes free
    

    正如所见,我不得不耍点小把戏( )因为我不能(至少我不认为我可以)修改 .exe文件

    四。测试

    这是一个可选阶段,以确保:

    [prompt]> .\cmake --help >nul 2>&1
    
    [prompt]> echo %errorlevel%
    0
    
    [prompt]> .\ResourceHacker.exe -help
    
    [prompt]>
    
    ==================================
    Resource Hacker Command Line Help:
    ==================================
    
    -help             : displays these abbreviated help instructions.
    -help commandline : displays help for single commandline instructions
    -help script      : displays help for script file instructions.
    
    
    
    
    [prompt]> echo %errorlevel%
    0
    

    还有他们的 :

    Img1-Final

        10
  •  3
  •   CharlesB Craig McQueen    12 年前

    Resource Tuner Console 来自Heaventools软件。

    资源调谐器控制台是一个命令行工具,它使开发人员能够在大量的Windows 32位和64位可执行文件中自动编辑不同的资源类型。

    具体见 Changing Version Variables And Updating The Version Information

        11
  •  2
  •   Tom Gordon    9 年前

    晚会有点晚了,但是因为我正在寻找它(我可能需要在某个时候再找到它),下面是我在VS2013 Express下把版本、公司名称等包括到我的C++ DLL中:

    1. 创建并编辑dllproj.rc文件,如前所述。
    2. 在DLL中添加了行“rc.exe dllproj.rc”作为预构建步骤
    3. 已将dllproj.res添加到项目的资源文件夹中。

        12
  •  2
  •   Subash J    6 年前

    你可以试着下载 FVIE公司 Download Link 并尝试编辑任何.exe文件的信息。

    (或)

    你可以下载 Download Link 这对windows.exe文件非常有用。

    您可以使用名为 资源编辑 Github Source link 然后使用Visual Studio 2015生成,然后您可以使用特定命令更改.exe文件的版本。见 Docs link 用于各种可用的命令。

        13
  •  1
  •   Community CDub    7 年前

    这是我见过的最好的工具,可以完全控制所有文件资源,包括VersionInfo。

    见: ResourceEditor Anders Melander .

        14
  •  0
  •   I_Al-thamary    6 年前

    有很多工具 reverse engineering Interactive Disassembler 您可以在其中更改更多信息以获取更多工具来查看此信息: https://www.apriorit.com/dev-blog/366-software-reverse-engineering-tools . 试试这些工具 https://alternativeto.net/software/xn-resource-editor/

        15
  •  0
  •   RDR    5 年前

    这个 above 我把它放在批处理文件里,效果很好

        @echo off
        :start1
        set /p newVersion=Enter version number [?.?.?.?]:
        if "%newVersion%" == "" goto start1
        :start2
        set /p file=Enter EXE name [for 'program.exe' enter 'program']:
        if "%file%" == "" goto start2
        set newVersion=%newVersion%
        for /f "tokens=1-4 delims=." %%a in ('echo %newVersion%') do (set ResVersion=%%a,%%b,%%c,%%d)
        (
        echo:VS_VERSION_INFO VERSIONINFO
        echo:    FILEVERSION    %ResVersion%
        echo:    PRODUCTVERSION %ResVersion%
        echo:{
        echo:    BLOCK "StringFileInfo"
        echo:    {
        echo:        BLOCK "040904b0"
        echo:        {
        echo:            VALUE "CompanyName",        "MyCompany\0"
        echo:            VALUE "FileDescription",    "TestFile\0"
        echo:            VALUE "FileVersion",        "%newVersion%\0"
        echo:            VALUE "LegalCopyright",     "COPYRIGHT © 2019 MyCompany\0"
        echo:            VALUE "OriginalFilename",   "%file%.exe\0"
        echo:            VALUE "ProductName",        "Test\0"
        echo:            VALUE "ProductVersion",     "%newVersion%\0"
        echo:        }
        echo:    }
        echo:    BLOCK "VarFileInfo"
        echo:    {
        echo:        VALUE "Translation", 0x409, 1200
        echo:    }
        echo:}
        ) >Resources.rc     &&      echo setting Resources.rc
        ResourceHacker.exe -open resources.rc -save resources.res -action compile -log CONSOLE
        ResourceHacker -open "%file%.exe" -save "%file%Res.exe" -action addoverwrite -resource "resources.res"  -log CONSOLE
        ResourceHacker.exe -open "%file%Res.exe" -save "%file%Ico.exe" -action addskip -res "%file%.ico" -mask ICONGROUP,MAINICON, -log CONSOLE
        xCopy /y /f "%file%Ico.exe" "%file%.exe"
        echo.
        echo.
        echo your compiled file %file%.exe is ready
        pause
    

    [顺便说一句,我也用资源黑客来编译res文件,而不是GoRC]