StampVer – Win32 Version Resource Stamping

Introduction

StampVer was written to allow easy stamping of a build number into the version resource of a Win32 executable. This build number can be specified on the command line, or via a response file. If a response file is used, StampVer can autoincrement the version number contained it it.

This can be useful if you are frequently passing application builds around and want something more definitive than file dates to determine which version someone has.

Note that this works directly on the final EXE – as it does not make changes to your source files, your resources do not need to be recompiled. In other words, it’s fast!

History

v1.40 Sep 99
  • PE checksum is now updated (uses the ImageHlp DLL).
  • Can update a response file without updating an EXE
  • v1.30 Jun 98
  • Improved error reporting for .inf file parsing.
  • Added readme information about better DevStudio integration.
  • Added strftime style date support to format specs
  • v1.20 Feb 98
  • Added support for zero padding, e.g. 1.05.0047
  • Allowed %a,%b,… to be used instead of %1,%2,… in format specifications to clarify them when using the zero padding feature!
  • Version strings are now padded to the maximum length with spaces. Use -nopad to disable this.
  • v1.10 Jan 98
  • -s param became -f (stamp explicit file version)
  • -p param altered (now stamps explicit product version)
  • -j param added (increment product version)
  • ProductVersion field added to response file
  • FileFormat field added to response file
  • ProductFormat field added to response file
  • -k param added (keep timestamp)
  • Default information level is -o2 rather than -o3
  • v1.00 Nov 97
  • First release.
  • Syntax and options

    StampVer [options] 
    -? displays this message
    -f"1.2.3.4" stamp with specified file version number, e.g. -f"2.10.0.0"
    -p"1.2.3.4" stamp with specified product version number, e.g. -p"2.10.0.0"
    -v"" get version number from response file, e.g. -v"stampver.inf"
    -i[1|2|3|4] preincrement file version number in response file
    1,2,3,4 correspond to a element of the version number, so
    to increment the minor version, use -i4. Useful for
    auto-incrementing a build number.
    -j[1|2|3|4] preincrement product version number in response file (as above).
    -k keep original file timestamp
    -nopad prevent padding of version strings with spaces.
    -o[1|2|3|4] sets the amount of output produced:
    -o1 errors only
    -o2 show warnings
    -o3 show informational messages
    -o4 show verbose diagnostics
    Quotes around parameters are optional unless the parameter contains spaces.
    
    

    About StampVer response files

    The response file is a simple text file that contains the last version number that was applied. Here is an example:

    ;StampVer information file
    FileVersion=1.0.0.4
    ProductVersion=5.0.0.4
    FileFormat=%a.%b.%c Build %04d
    ProductFormat=%a.%b.%c Build %04d
    
    

    The response file allows you to have separately maintained file and product numbers. If you do not wish to stamp either the file or product number, then simply ensure the response file does not contain that entry!

    The FileFormat and ProductFormat entries are optional, but if present they allow you to customise the format of the version strings. These entries are vaguely similar to printf format specs. The default is simply %a.%b.%c.%d. You can add zero padding to a field by specifying a zero followed by the required field width, e.g. %04d would expand to something like 0047.

    You can also embed date and time information into the version strings using strftime style format specs preceded by a %t. For example

    FileFormat=%a.%b Build %04d (%td %tb)
    
    

    would produce something like this:

    1.23 Build 456 (23 Jan)
    
    

    Here are some common strftime codes you could use:

    %ta   Abbreviated weekday name
    %td   Day of month (01-31)
    %tj   Day of year (001-366)
    %tm   Month (01-12)
    %tb   Abbreviated month name
    %ty   Year without century (00-99)
    %tY   Year with century
    %tH   Hour in 24-hour format (00-23)
    %tM   Minute (00-59)
    %tS   Second (00-59)
    
    

    Check your C run time strftime documentation for others. Remember to insert the t though!

    If you specify a response file that doesn’t exist, or do not specify one at all, one will be created for you in the current directory with the name stampver.inf

    Note that if you use the -f or -p options these will override any response file settings.

    Integrating with Microsoft Developer Studio

    You can set up StampVer to autoincrement build numbers as part of your normal build process. Assuming that your EXE has a version resource, and StampVer is on the path, you simply set up a custom build step for the target.

    To do this, get the project settings dialog (Alt-F7), highlight the top level folder for a build, and select the Custom Build tab. Add a build command that looks like this:

    StampVer -vstampver.inf -i4 -j4 $(TargetPath)
    
    

    Set the output file to be the following:

    $(WkspDir)dummy
    
    

    These settings will store the version number in stampver.inf file in the workspace directory, and will autoincrement the version numbers contained in it before applying it to the FileVersion and ProductVersion elements of the target EXE.

    NOTE: Here an alternative technique, that will work no matter what StampVer options are used (the above only works with the -i or -j options, as they cause stampver.inf to be updated)

    StampVer -vstampver.inf $(TargetPath)
    echo stampver executed > "$(OutDir)\stampver.trg"
    
    

    And set the output file to the following:

    $(OutDir)\stampver.trg
    
    

    This is a general purpose technique that can be used for any tool that doesn’t produce an output file.

    FAQ

    Q: StampVer complains that my application doesn’t have a version resource

    A: Please note that StampVer only operates on Win32 exe/dll files that already have a version resource. It cannot add a version resource if one doesn’t exist.

    Q: StampVer says that there isn’t enough space for the version strings

    A: StampVer can only update the FileVersion and ProductVersion strings if there is enough space to do so – it is not capable of making the version strings larger than they already are. An easy way to ensure this is to set your version resource to contain 000.000.000.000 for these strings, and let StampVer overwrite these with the real version numbers.

    StampVer will pad version strings to their maximum length with spaces. This feature can be disabled with the -nopad option. This was added when it was found that Dev Studio 4.0 crashed when it tries to display the version resource for an EXE that StampVer has processed.

    Q: My incremental linker doesn’t work anymore

    A: Since StampVer changes the exe file, it may confuse your incremental linker into never linking incrementally.

    Note that from v1.4, StampVer will update the EXE/DLL checksum. The NT loader is picky about this for core system DLLs, and no doubt Win2000 will be too. StampVer uses the ImageHlp dll to perform this task.

    Q: How do I use StampVer with Visual Basic executables?

    A: I get the occasional email reporting the StampVer doesn’t work with executables produced with Visual Basic. To cut a long story short, StampVer works on any I386 based Portable Executable file with a valid version resource. In other words, if you can view the file property sheet for and see a version tab, chances are StampVer can do something for you.

    The reason VB users report this ‘bug’ is that their projects get a version string of the form aaaa.bbbb.cccc. If you don’t use a similar StampVer format spec, you can run into the ‘not enough space for updated string’ problem. So use a response file a bit like this…

    ;StampVer information file
    FileVersion=1111.2222.3333.0
    ProductVersion=1111.2222.3333.0
    FileFormat=%a.%b.%c
    ProductFormat=%a.%b.%c
    

    Download

    StampVer is freeware, and comes with no warranty – you use it at your own risk. If you do experience problems, or have ideas for enhancements, please get in touch.

    stampver.zip 33kb

    4 thoughts on “StampVer – Win32 Version Resource Stamping

    1. Yvee

      Hello – the download page link leads right back to this page. Is the version on codeguru the latest? Thanks!

    2. JM

      Hello, I’d like to be able to edit …

      BLOCK “040904b0”
      {
      VALUE “CompanyName”, “ACME Inc.”
      VALUE “FileDescription”, “MyProg”
      VALUE “FileVersion”, “1.0.0.0”
      VALUE “LegalCopyright”, “© 2013 ACME Inc. All Rights Reserved”
      VALUE “OriginalFilename”, “MyProg.exe”
      VALUE “ProductName”, “My Program”
      VALUE “ProductVersion”, “1.0.0.0”
      }

      …from a batch file. Can your utility do this?

    Leave a Reply

    Your email address will not be published.