获得文件版本信息

//MMWIN:MODULECOPY

unit _MM_Copy_Buffer_;

interface


implementation

procedure GetBuildInfo(var AProductName, AVer, ALegalCopyright: string);
var
VerInfoSize: DWORD;
GetInfoSizeJunk: DWORD;
VersionInfo: Pointer;
Translation: Pointer;
InfoPointer: Pointer;
VersionInfoSize: UINT;
VersionValue: string;
begin
AProductName := '默认名称';
ALegalCopyright := 'Copyright(C) xxxx有限公司。2008';
AVer := '---';

VerInfoSize := GetFileVersionInfoSize(Pchar(ParamStr(0)), GetInfoSizeJunk);
if VerInfoSize <= 0 then
Exit;

GetMem(VersionInfo, VerInfoSize);
try
GetFileVersionInfo(Pchar(ParamStr(0)), 0, VerInfoSize, VersionInfo);
//得到文件的版本资源
VerQueryValue(VersionInfo, '""VarFileInfo""Translation',
Translation, VersionInfoSize);
VersionValue := '""StringFileInfo""' +
IntToHex(LoWord(LongInt(Translation^)), 4) +
IntToHex(HiWord(LongInt(Translation^)), 4) +
'""';

VerQueryValue(VersionInfo, PChar(VersionValue + 'FileVersion'),
InfoPointer, VersionInfoSize);
AVer := string(PChar(InfoPointer));

VerQueryValue(VersionInfo, PChar(VersionValue + 'LegalCopyright'),
InfoPointer, VersionInfoSize);
ALegalCopyright := string(PChar(InfoPointer));

VerQueryValue(VersionInfo, PChar(VersionValue + 'ProductName'),
InfoPointer, VersionInfoSize);
AProductName := string(PChar(InfoPointer));

finally
FreeMem(VersionInfo, VerInfoSize);
end;

end;

end.

提取其他字段方法,方法相同。只要修改一下名字就可以了

OriginalFilename //原文件名称
CompanyName //公司名称 
FileDescription //文件描述
FileVersion //文件的版本
InternalName //内部名称 
LegalCopyright //合法版权
LegalTrademarks //合法商标
ProductName //产品名称
ProductVersion //产品版本
Comments //备注 

 

posted @ 2008-07-18 09:59  cmacro  阅读(653)  评论(0编辑  收藏  举报