Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the version information for an existing .exe, .dll?

People also ask

How do I check the version of an EXE file?

For example, Oracle Java has the java.exe file, CCleaner has ccleaner.exe and so on. Right click on it and then select Properties. In the Properties window, go to the Details tab. There you will find information about the product name, the product version and so on.

How do I find a DLL version?

If you reference the dll in Visual Studio right click it (in ProjectName/References folder) and select "Properties" you have "Version" and "Runtime Version" there. In File Explorer when you right click the dll file and select properties there is a "File Version" and "Product Version" there.

Is Exe the same as DLL?

EXE is an extension used for executable files while DLL is the extension for a dynamic link library. 2.An EXE file can be run independently while a DLL is used by other applications. 3. A DLL file can be reused by other applications while an EXE cannot.


While it's not a batch process, Visual Studio can also add/edit file resources.

Just use File->Open->File on the .EXE or .DLL. This is handy for fixing version information post-build, or adding it to files that don't have these resources to begin with.


Unlike many of the other answers, this solution uses completely free software.

Firstly, create a file called Resources.rc like this:

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

Next, use GoRC to compile it to a .res file using:

GoRC /fo Resources.res Resources.rc

(see my comment below for a mirror of GoRC.exe)

Then use Resource Hacker in CLI mode to add it to an existing .exe:

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

That's it!


Or you could check out the freeware StampVer for Win32 exe/dll files.
It will only change the file and product versions though if they have a version resource already. It cannot add a version resource if one doesn’t exist.


rcedit is relative new and works well from the command line: 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"

There's also an NPM module which wraps it from JavaScript and a Grunt task in case you're using Grunt.


What about something like this?

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

Available here with full sources.


There are multiple tools, mentioned by many great answers, I'm going to pick one.

Resource Hacker

I downloaded latest version (5.1.7) from [AngusJ]: Resource Hacker. All the needed information can be found on that page (command line options, scripts, ...). In the following walkthrough I'm going to operate on 2 executables (lab rats) which (for obvious reasons) I've copied in my cwd:

  • ResourceHacker.exe: I thought it would be interesting to operate on itself
  • cmake.exe: random executable with no Version Info set (part of v3.6.3 installation on my machine)

Before going further, I want to mention that ResourceHacker has a funny terminal output, and the the following copy / paste fragments might generate a bit of confusion.

1. Setup

This is more like a preliminary step, to get acquainted with the environment, to show there's no funky business going on, ...

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

As seen, the executables are OK, they run fine, and here's how their Details (that we care about) look like:

Img0-Initial

2. Resources

Resource files are text files that contain resources. A resource (simplified) has:

  • Name
  • Type
  • Value

For more details check [MS.Docs]: About Resource Files. There are many tools (mentioned in existing answers) that facilitate resource file editing like:

  • VStudio creates a default one when starting a new project
  • One can create such a file manually
  • But, since it's about Resource Hacker, and:

    • It is able to extract resources from an existing executable
    • It has resources embedded in it (as shown in the previous picture)

    I'm going to use it for this step (-action extract)

Next, In order for a resource to be embedded into an .exe (.dll, ...) it must be compiled to a binary form, which fits into the PE format. Again, there are lots of tools who can achieve this, but as you probably guessed I'm going to stick to Resource Hacker (-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

In your case saving and editing the resource file won't be necessary, as the file will already be present, I just did it for demonstrating purposes. Below it's the resource file after being modified (and thus before being compiled).

sample.rc:

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

3. Embed

This will also be performed by Resource Hacker (-action addoverwrite). Since the .exes are already copied I'm going to edit their resources in place.

[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

As seen, I had to d a little trick (gainarie) as I can't (at least I don't think I can) modify the .exe while in use.

4. Test

This is an optional phase, to make sure that:

  • The executables still work (they weren't messed up in the process)
  • The resources have been added / updated
[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

And their Details:

Img1-Final