取应用程式的版本号
【打印文章】
function GetAppVersion:String;
{取应用程式的版本号程式,如有版本号,返回值为版本号的值,否则返回值为空
返回值的格式为如1.0.0.0
胡国荣 2000/11/04 }
function GetFileVersion(FileName: string): string;
type
PVerInfo = ^TVS_FIXEDFILEINFO;
TVS_FIXEDFILEINFO = record
dwSignature: longint;
dwStrucVersion: longint;
dwFileVersionMS: longint;
dwFileVersionLS: longint;
dwFileFlagsMask: longint;
dwFileFlags: longint;
dwFileOS: longint;
dwFileType: longint;
dwFileSubtype: longint;
dwFileDateMS: longint;
dwFileDateLS: longint;
end;
var
ExeNames: array[0..255] of char;
zKeyPath: array[0..255] of Char;
VerInfo: PVerInfo;
Buf: pointer;
Sz: word;
L, Len: Cardinal;
begin
StrPCopy(ExeNames, FileName);
Sz := GetFileVersionInfoSize(ExeNames, L);
if Sz=0 then
begin
Result:='';
Exit;
end;
try
GetMem(Buf, Sz);
try
GetFileVersionInfo(ExeNames, 0, Sz, Buf);
if VerQueryValue(Buf, '\', Pointer(VerInfo), Len) then
begin
Result := IntToStr(HIWORD(VerInfo.dwFileVersionMS)) + '.' +
IntToStr(LOWORD(VerInfo.dwFileVersionMS)) + '.' +
IntToStr(HIWORD(VerInfo.dwFileVersionLS)) + '.' +
IntToStr(LOWORD(VerInfo.dwFileVersionLS));
end;
finally
FreeMem(Buf);
end;
except
Result := '-1';
end;
end;
begin
Result:=GetFileVersion(Application.ExeName);
end;
{取应用程式的版本号程式,如有版本号,返回值为版本号的值,否则返回值为空
返回值的格式为如1.0.0.0
胡国荣 2000/11/04 }
function GetFileVersion(FileName: string): string;
type
PVerInfo = ^TVS_FIXEDFILEINFO;
TVS_FIXEDFILEINFO = record
dwSignature: longint;
dwStrucVersion: longint;
dwFileVersionMS: longint;
dwFileVersionLS: longint;
dwFileFlagsMask: longint;
dwFileFlags: longint;
dwFileOS: longint;
dwFileType: longint;
dwFileSubtype: longint;
dwFileDateMS: longint;
dwFileDateLS: longint;
end;
var
ExeNames: array[0..255] of char;
zKeyPath: array[0..255] of Char;
VerInfo: PVerInfo;
Buf: pointer;
Sz: word;
L, Len: Cardinal;
begin
StrPCopy(ExeNames, FileName);
Sz := GetFileVersionInfoSize(ExeNames, L);
if Sz=0 then
begin
Result:='';
Exit;
end;
try
GetMem(Buf, Sz);
try
GetFileVersionInfo(ExeNames, 0, Sz, Buf);
if VerQueryValue(Buf, '\', Pointer(VerInfo), Len) then
begin
Result := IntToStr(HIWORD(VerInfo.dwFileVersionMS)) + '.' +
IntToStr(LOWORD(VerInfo.dwFileVersionMS)) + '.' +
IntToStr(HIWORD(VerInfo.dwFileVersionLS)) + '.' +
IntToStr(LOWORD(VerInfo.dwFileVersionLS));
end;
finally
FreeMem(Buf);
end;
except
Result := '-1';
end;
end;
begin
Result:=GetFileVersion(Application.ExeName);
end;
本栏文章均来自于互联网,版权归原作者和各发布网站所有,本站收集这些文章仅供学习参考之用。任何人都不能将这些文章用于商业或者其他目的。( Pfan.cn )
【编程爱好者论坛】