如何在Delphi中向另一个exe添加版本信息? [英] How to add version informations to another exes in Delphi?

查看:411
本文介绍了如何在Delphi中向另一个exe添加版本信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试使用BeginUpdateResource / UpdateResource(对于特定语言),另外一个exes没有这样的信息/ EndUpdateResource,但所有我成功的是创建版本>> 1 >>未知字符串,而不是版本>> 1 >>公司名称/版本号/描述...及其值。



我在Google和这里搜索,但找不到有用的东西。只有不完整的代码,我不知道如何完成。



谢谢。



编辑:



以下是我现在使用的代码:

  procedure SetExeInfo(const ExeName,ResName,ResValue:string); 
var
ResourceHandle:THandle;
DataLength:DWord;
数据:Char数组;
Ok:Boolean;
i:整数;

begin
ResourceHandle:= BeginUpdateResource(pChar(ExeName),False);
if(ResourceHandle<> 0)then
begin
DataLength:= 8;
SetLength(数据,8);
for i:= 0 to 7 do
Data [i]:='z';
Ok:= True;
if(not UpdateResource(ResourceHandle,RT_VERSION,pChar(#49#0),LANG_SYSTEM_DEFAULT {MakeLangID(LANG_NEUTRAL,SUBLANG_NEUTRAL)},Data,DataLength))然后
Ok:= False;

if(not EndUpdateResource(ResourceHandle,False))然后
Ok:= False;

if(Ok)then
ShowMessage('Update of resources successful!')
else
ShowMessage('资源更新失败!

end;
结束

上次修改


$ b $我没有在我的问题中指出我不能从另一个exe转移信息,因为我没有看到这样做,因为我没有具体说我从另一个exe获取版本信息可执行程序。看来我错了,对不起,

解决方案

以下是一些增加或替换版本号码的工作代码:

 键入
VERSIONHEADER =打包记录
wLength:word;
wValueLength:word;
wType:word;
Key:Array [0..16] of WideChar; //'VS_VERSION_INFO'
版本:VS_FIXEDFILEINFO;
结束

(...)
var ToolPath:TFileName; // = exe包含引用版本资源
ExeFullPath:TFileName; // = destination exe
Maj,Min:cardinal; // expected UPDATED版本号
VersionHandle,VersionRes:THandle;
VersionSize:DWORD;
版本:AnsiChar的数组;
版本:^ VERSIONHEADER;
(...)
VersionSize:= GetFileVersionInfoSize(pointer(ToolPath),VersionHandle);
if(VersionSize<>>> 0)和(Maj<> 0)then
begin
SetLength(Version,VersionSize);
Ver:= pointer(Version);
GetFileVersionInfo(指针(ToolPath),0,VersionSize,Ver);
如果Ver ^ .Version.dwSignature = $ feef04bd然后
begin
Ver ^ .Version.dwFileVersionMS:= MAKELONG(Min,Maj);
Ver ^ .Version.dwProductVersionMS:= Ver ^ .Version.dwFileVersionMS;
VersionRes:= BeginUpdateResource(指针(ExeFullPath),False);
UpdateResource(VersionRes,RT_VERSION,MAKEINTRESOURCE(VS_VERSION_INFO),
1033,Ver,VersionSize);
EndUpdateResource(VersionRes,false);
结束
结束

它将添加或更新现有可执行文件的数字版本号( ExeFullPath ),将其替换为提供的可执行资源( ToolPath - 可能 paramstr(0) ExeFullPath 来更新版本号)。


I want to add version informations (for a specific language) to another exes that does not have such informations (at all).

I tried with BeginUpdateResource/UpdateResource/EndUpdateResource but all I succedeed is to create "Version >> 1 >> Unknown string", not "Version >> 1 >> CompanyName/VersionNumber/Description..." and their values.

I searched on Google and here but I couldn't find something useful. Only incomplete code which I didn't know how to finish.

Thank you.

Edit:

Here is the code that I use now:

procedure SetExeInfo(const ExeName, ResName, ResValue: string);
var
   ResourceHandle: THandle;
   DataLength: DWord;
   Data: array of Char;
   Ok: Boolean;
   i: Integer;

begin
   ResourceHandle := BeginUpdateResource(pChar(ExeName), False);
   if (ResourceHandle <> 0) then
   begin
      DataLength := 8;
      SetLength(Data, 8);
      for i := 0 to 7 do
         Data[i] := 'z';
      Ok := True;
      if (not UpdateResource(ResourceHandle, RT_VERSION, pChar(#49#0), LANG_SYSTEM_DEFAULT {MakeLangID(LANG_NEUTRAL, SUBLANG_NEUTRAL)}, Data, DataLength)) then
         Ok := False;

      if (not EndUpdateResource(ResourceHandle, False)) then
         Ok := False;

      if (Ok) then
         ShowMessage('Update of resources successful!')
      else
         ShowMessage('Update of resources failed!');

   end;
end;

Last edit:

I haven't specified in my question that I can't transfer the informations from another exe because I haven't seen the point to do this, since I haven't said specifically that I take the version info from another exe. Looks I was wrong, sorry.

解决方案

Here is some working code to add or replace the version numbers:

type
 VERSIONHEADER = packed record
   wLength: word;
   wValueLength: word;
   wType: word;
   Key: array[0..16] of WideChar;   // 'VS_VERSION_INFO'
   Version: VS_FIXEDFILEINFO;
 end;

  (...)
  var ToolPath: TFileName;    // = exe containing a reference version resource
      ExeFullPath: TFileName; // = destination exe
      Maj, Min: cardinal; // expected UPDATED Version number
      VersionHandle, VersionRes: THandle;
      VersionSize: DWORD;
      Version: array of AnsiChar;
      Ver: ^VERSIONHEADER;
  (...)
  VersionSize := GetFileVersionInfoSize(pointer(ToolPath),VersionHandle);
  if (VersionSize<>0) and (Maj<>0) then
  begin
    SetLength(Version,VersionSize);
    Ver := pointer(Version);
    GetFileVersionInfo(pointer(ToolPath),0,VersionSize,Ver);
    if Ver^.Version.dwSignature=$feef04bd then
    begin
      Ver^.Version.dwFileVersionMS := MAKELONG(Min,Maj);
      Ver^.Version.dwProductVersionMS := Ver^.Version.dwFileVersionMS;
      VersionRes := BeginUpdateResource(Pointer(ExeFullPath),False);
      UpdateResource(VersionRes,RT_VERSION,MAKEINTRESOURCE(VS_VERSION_INFO),
        1033,Ver,VersionSize);
      EndUpdateResource(VersionRes,false);
    end;
  end;

It will add or update the numeric version numbers of an existing executable (ExeFullPath), replacing it with a supplied executable resource (ToolPath - may be paramstr(0) to copy some existing generic version information, or even ExeFullPath to update the version numbers).

这篇关于如何在Delphi中向另一个exe添加版本信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆