Delphi code to get program version
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
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; |