获取一个文件的版本信息
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
摘自 一刀日记
补充:软件开发 , Delphi ,