Share this page 

Set and retrieve the executable versionTag(s): WinAPI/Registry


On Windows, the properties tab on an executable can show a version number. By default, an executable produced by Powerbuilder shows the Powerbuilder version number not the version of the executable itself.

Here a way to embed your own version number. By reading it back, it's possible to validate if the executable is the current one against a special table in your application's database for example.


You need a special utility to change the version of the executable. A freeware utility to do that can be downloaded from http://www.elphin.com/downloads/stampver/.

Create a response file to contains you version number with the right formatting (in this example, only the first 3 numbers are used).

;StampVer information file (myapp.inf)
FileVersion=1.0.2.0
FileFormat=%02a.%02b.%02c
Now you can the version number with
stampver -v"myapp.inf" myapp.exe
Showing the properties/version tab for this executable will show your version number and not the Sybase one now.

This freeware can deal only with the file version, not the product information or any other infos shown on properties/version tab. To change these values, look at the Crane computing site, they have product that can do that with a nice gui interface.


To retrieve the version from an executable :
[local external function declaration]
FUNCTION ulong GetFileVersionInfoSizeA &
   ( REF string lpFilename, REF ulong lpdwHandle ) &
   LIBRARY "version.dll"

FUNCTION integer GetFileVersionInfoA &
   ( REF string lpFilename, REF ulong lpdwHandle, ulong dwLen, &
     REF string lpData )  &
   LIBRARY "version.dll"

FUNCTION boolean VerQueryValueA &
   ( REF string lpBlock, string lpSubBlock, REF long lpBuffer, &
     REF uint puLen )  &
    LIBRARY "version.dll"

SUBROUTINE CopyMemory &
   ( REF string d, long s, long l )  &
   LIBRARY "kernel32.dll"  &
   ALIAS FOR RtlMoveMemory
[powerscript]
ulong  dwHandle, dwLength
string ls_Buff, ls_key, ls_versioninfo
uint   lui_length
long   ll_pointer
string as_filename = "d:\dev\pb6\myapp.exe"
integer li_rc


dwLength = GetFileVersionInfoSizeA( as_filename, dwHandle )
IF dwLength <= 0 THEN
   RETURN
END IF

ls_Buff = Space( dwLength )

li_rc = GetFileVersionInfoA( as_filename, dwHandle, dwLength, ls_Buff )

IF li_rc = 0 THEN
    RETURN
END IF

// the strange numbers below represents the country and language
// of the version ressource.
ls_key = "\StringFileInfo\040904e4\FileVersion"
IF NOT VerQueryValueA( ls_buff, ls_key, ll_pointer, lui_length ) OR &
    lui_length <= 0 THEN
    ls_versioninfo = "?"
ELSE
    ls_versioninfo = Space( lui_length )
    CopyMemory( ls_versioninfo, ll_pointer, lui_length )
END IF

Messagebox("version", ls_versioninfo)