function ReadVersionInfo:string;
type
Translate=record
wLanguage:WORD;
wCodePage:WORD;
end;
lpTranslate=^Translate;
var
AppFileName,RequestInfo:string;
VersionInfoSize,varDummy,VersionSize,cbTranslate:Cardinal;
VersionInfo,pVersion:PAnsiChar;
pTranslate:lpTranslate;
begin
Result:='';
AppFileName:=Application.ExeName;
VersionInfoSize:=GetFileVersionInfoSize(PAnsiChar(AppFileName),varDummy);
if VersionInfoSize>0 then
begin
GetMem(VersionInfo,VersionInfoSize);
if GetFileVersionInfo(PAnsiChar(AppFileName),varDummy,VersionInfoSize,VersionInfo) then
begin
if VerQueryValue(VersionInfo,pchar('\VarFileInfo\Translation'), Pointer(pTranslate),cbTranslate) then
begin
RequestInfo := format('\StringFileInfo\%.4x%.4x\ProductVersion',[pTranslate^.wLanguage,pTranslate^.wCodePage]);
if VerQueryValue(VersionInfo, PAnsiChar(RequestInfo),Pointer(pVersion), VersionSize) then
Result:=pVersion;
end;
end;
FreeMem(VersionInfo);
end;
end;
以上代碼放到delphi 項目裡應該可以直接用,如果你想獲取更多信息,請參考 VerQueryVaule 函數的使用幫助。
VerQueryVaule 的msdn幫助地址
http://msdn.microsoft.com/en-us/library/windows/desktop/ms647464%28v=vs.85%29.aspx
摘自 一刀日記