The information on the version Exe-file I receive by means of VerQueryValue. Is there an inverse function (WinApi or Delphi) which can register (establish or change) such information? Here, for example, there is a program which is able to do so. How may it work (http://www.angusj.com/resourcehacker)?
Asked
Active
Viewed 2,878 times
6
-
1This is determined by the [version resource](http://msdn.microsoft.com/en-us/library/aa381058(VS.85).aspx). Use [`UpdateResource`](http://msdn.microsoft.com/en-us/library/ms648049(VS.85).aspx) to modify it. – David Heffernan Oct 17 '11 at 16:08
-
1Here's a link to a program with source how to set the version info. Delphi 2009 and up compatible. [updated-setversion-exe-to-set-file-version-info-in-res-or-exe](http://www.jasontpenny.com/blog/2009/09/05/updated-setversion-exe-to-set-file-version-info-in-res-or-exe/) – LU RD Oct 17 '11 at 16:20
1 Answers
12
The version information is stored via resources; to edit that you simply need to edit that resource. Here is a unit I found that can clone an existing file version information and attach it to another file. It's very easy to do what you want starting from this code (it's coded by a friend of mine and is available public):
unit cloneinfo;
interface
uses Windows, SysUtils;
type
LANGANDCODEPAGE = record
wLanguage: Word;
wCodePage: Word;
end;
procedure clone(sFile,output:string);
implementation
procedure clone(sFile,output:string);
var
dwHandle, cbTranslate: cardinal;
sizeVers: DWord;
lpData, langData: Pointer;
lpTranslate: ^LANGANDCODEPAGE;
hRes : THandle;
begin
sizeVers := GetFileVersionInfoSize(PChar(sFile), dwHandle);
If sizeVers = 0 then
exit;
GetMem(lpData, sizeVers);
try
ZeroMemory(lpData, sizeVers);
GetFileVersionInfo (PChar(sFile), 0, sizeVers, lpData);
If not VerQueryValue (lpData, '\VarFileInfo\Translation', langData, cbTranslate) then
exit;
hRes := BeginUpdateResource(pchar(output), FALSE);
//For i := 0 to (cbTranslate div sizeof(LANGANDCODEPAGE)) do
//begin
lpTranslate := Pointer(Integer(langData) + sizeof(LANGANDCODEPAGE));
UpdateResource(hRes, RT_VERSION, MAKEINTRESOURCE(VS_VERSION_INFO), lpTranslate^.wLanguage,lpData, sizeVers);
//end;
EndUpdateResource(hRes, FALSE);
finally
FreeMem(lpData);
end;
end;
end.
-
It's just for language and code page information. What about [VS_FIXEDFILEINFO](http://msdn.microsoft.com/en-us/library/ms646997%28v=VS.85%29.aspx) ? +1 anyway – TLama Oct 17 '11 at 16:17
-
1If this is a unit that you found on the Internet, you need to be more careful with the licensing. At the very, very least, you should provide a link to the source. (In addition, have a look at http://en.wikipedia.org/wiki/Run-on_sentence.) – Andreas Rejbrand Oct 17 '11 at 16:49
-
@opc0de, all well and good for you, but without a statement from the author saying that it's free to use, it's "found on the internet" for the rest of us. Upvote pending resolution.... – Chris Thornton Oct 17 '11 at 17:22
-
@Chris In order to get rid of the license, it is very easy to recode it from scratch to get your own version (using an array of bytes instead of a pointer+getmem+zeromemory+freemem for instance). It is just a wrapper around Windows API. Nice code in all cases. +1 – Arnaud Bouchez Oct 17 '11 at 18:05
-
I usually don't copy and paste code but calling some api's i don't think should be in the incidence of a copyright if this was an algorithm or something hard to do i would agree.As Arnaud pointed i could cut some apis or replace them with synonyms and voila code written by me. – opc0de Oct 17 '11 at 19:06
-