Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I most strongly recommend not to use GetFileVersion when you want to know the version of the executable that is currently running! I have two pretty good reasons to do this:</p> <ol> <li>The executable may be unaccessible (disconnected drive/share), or changed (.exe renamed to .bak and replaced by a new .exe without the running process being stopped).</li> <li>The version data you're trying to read has actually already been loaded into memory, and is available to you by loading this resource, which is always better than to perform extra (relatively slow) disk operations.</li> </ol> <p>To load the version resource in Delphi I use code like this:</p> <pre><code>uses Windows,Classes,SysUtils; var verblock:PVSFIXEDFILEINFO; versionMS,versionLS:cardinal; verlen:cardinal; rs:TResourceStream; m:TMemoryStream; p:pointer; s:cardinal; begin m:=TMemoryStream.Create; try rs:=TResourceStream.CreateFromID(HInstance,1,RT_VERSION); try m.CopyFrom(rs,rs.Size); finally rs.Free; end; m.Position:=0; if VerQueryValue(m.Memory,'\',pointer(verblock),verlen) then begin VersionMS:=verblock.dwFileVersionMS; VersionLS:=verblock.dwFileVersionLS; AppVersionString:=Application.Title+' '+ IntToStr(versionMS shr 16)+'.'+ IntToStr(versionMS and $FFFF)+'.'+ IntToStr(VersionLS shr 16)+'.'+ IntToStr(VersionLS and $FFFF); end; if VerQueryValue(m.Memory,PChar('\\StringFileInfo\\'+ IntToHex(GetThreadLocale,4)+IntToHex(GetACP,4)+'\\FileDescription'),p,s) or VerQueryValue(m.Memory,'\\StringFileInfo\\040904E4\\FileDescription',p,s) then //en-us AppVersionString:=PChar(p)+' '+AppVersionString; finally m.Free; end; end; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload