Using Delphi to modify the version information of another delphi program

你离开我真会死。 提交于 2019-12-21 02:57:11

问题


I was wanting to create a small tool in Delphi which can update the Delphi version information in another exe file. I know several existing utilities are out there for this but I need full programmatic control and would prefer no shelling out to the command line, etc.

After a web search I couldn't find any Delphi source code examples of modifying version information in an exe, could anyone provide some code or direction?


回答1:


I can't give a complete answer, but I can get you started. There is an article at DelphiDabbler.com that fills in how to get to the version information out of a file. GetFileVersionInfo is the Windows API to do that. To set it, I believe UpdateResource is the Windows API function you'll need to use. There is another article at CodeProject that covers this, using C, but it should give you a solid idea of what needs to be done.

Good luck!

Edit: I found some code on the Delphi newsgroups that might give you some more help:

// Credit to Michael Winter for this code!
Sz := GetLen;
GetMem(Data, Sz);
try
  GetData(Data, Sz);
  HFile := BeginUpdateResource(PChar(FileName), false);
  if HFile = 0 then
    RaiseLastWin32Error;
  DoDiscard := true;
  try
    if not UpdateResource(HFile, RT_VERSION, PChar(1), 0, Data, Sz) then
      RaiseLastWin32Error;
    DoDiscard := false;
  finally
    if not EndUpdateResource(HFile, DoDiscard) then
      RaiseLastWin32Error;
  end;
finally
  FreeMem(Data);
end;

It's just a snippet, and will require some work on your part, but that's the lion's share of the work!




回答2:


There's also Colin Wilson's XN Resource Editor with source code which might help.



来源:https://stackoverflow.com/questions/762778/using-delphi-to-modify-the-version-information-of-another-delphi-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!