有时大家发现,现在有点流行如:Build 4.1.5.137这样的版本号。这样的版本号一般都不是手工输入了,而是提取的程序自身的版本号。程序自身的版本号在哪里控制呢?执行Project菜单下的“Options”功能,在打开的窗口中有一个“Version Info”页面,在这个页面中,用户可设定这四个版本号初始数据,也可以随时根据程序的功能是否有大的变化升级主版本和次版本号,将“Auto Increment build number”前的复选框选中,以后每当用户用Project菜单下的“Build all Projects”功能时,最后的build编号将自动增加1。一般来说,在前面的三个号不变时,最后的编号越大说明程序的更新时间最近。在这个页面上还有一些其他功能如公司名称等等可以设定,读者自己试试吧。现在我们来说明如何用代码获得这四个编号。下面是获取这四个版本号的通用函数代码,用户直接调用即可:function GetBuildInfo: string;var VerInfoSize: DWORD; VerInfo: Pointer; VerValueSize: DWORD; VerValue: PVSFixedFileInfo; Dummy: DWORD; V1, V2, V3, V4: Word;begin VerInfoSize := GetFileVersionInfoSize(PChar(ParamStr(0)), Dummy); if VerInfoSize = 0 then begin Dummy := GetLastError; Result := '0.0.0.0'; end; {if} GetMem(VerInfo, VerInfoSize); GetFileVersionInfo(PChar(ParamStr(0)), 0, VerInfoSize, VerInfo); VerQueryValue(VerInfo, '\', Pointer(VerValue), VerValueSize); with VerValue^ do begin V1 := dwFileVersionMS shr 16; V2 := dwFileVersionMS and $FFFF; V3 := dwFileVersionLS shr 16; V4 := dwFileVersionLS and $FFFF; end; Result := IntToStr(V1) + '.' + IntToStr(V2) + '.' + IntToStr(V3) + '.' + IntToStr(V4); FreeMem(VerInfo, VerInfoSize);end;调用示例:version.caption:='版本号: '+GetBuildInfo;//version是一个标签组件
请问要是得到发行公司,语言版本,之类的怎么办?
自己分析pe么?
http://www.obsof.com/public/download.html
GetFileVersionInfoSize
GetFileVersionInfo
VerQueryValue
Classes, StdCtrls;const
// Version keys description
vsCompanyName = 'CompanyName';
vsFileDescription = 'FileDescription';
vsInternalName = 'InternalName';
vsLegalCopyright = 'LegalCopyright';
vsLegalTrades = 'LegalTrades';
vsOriginalFilename = 'OriginalFilename';
vsProductName = 'ProductName';
vsComments = 'Comments';type
// Fixed File Information in Version section
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; TInfoCategory = (icVersion, icShortVersion, icCompanyName,
icFileDescription,
icInternalName, icLegalCopyright,
icLegalTrades, icOriginalFilename,
icProductName, icComments);// Version string viewer class definition
TVersionView = class(TLabel)
private
{ Private declarations }
FVersionText : string;
FInfoCategory: TInfoCategory;
procedure GetPrgInfo(AKey : string);
procedure GetPrgVer(AShort: boolean);
protected
{ Protected declarations }
function GetLabelText: string; override;
procedure SetName(const NewName: TComponentName); override;
public
{ Public declarations }
published
{ Published declarations }
property InfoCategory :TInfoCategory read FInfoCategory write FInfoCategory;
end;function GetVersionDigits(const AShort: boolean): string;
// Get version number from Version Inf. part of your Delphi program.
function GetVersionString(const AKey : string): string;
// Get ofter Viersion Inf. strings ...implementation
uses Windows, SysUtils, Forms, Dialogs;
var
VerInfoPresent : boolean;
Buf : pointer;
Sz : word;function TextConcate(S1, S2 : string): string;
begin
Result := S1;
if S2 = '' then exit;
if S1 = '' then Result := S2 else
Result := S1+' '+S2;
end;function SwapLong(L : longint): longint;
assembler;
asm
rol eax, 16;
end;procedure TVersionView.SetName;
begin
inherited;
Invalidate;
// Needed for changing component Name at Disign time
end;procedure TVersionView.GetPrgInfo;
begin
FVersionText := TextConcate(Caption, GetVersionString(AKey));
end;procedure TVersionView.GetPrgVer;
begin
FVersionText := TextConcate(Caption, GetVersionDigits(AShort));
end;function TVersionView.GetLabelText: string;
begin
if not (csDesigning in ComponentState) then
begin
case FInfoCategory of
icVersion : GetPrgVer(false);
icShortVersion : GetPrgVer(true);
icCompanyName : GetPrgInfo(vsCompanyName);
icFileDescription : GetPrgInfo(vsFileDescription);
icInternalName : GetPrgInfo(vsInternalName);
icLegalCopyright : GetPrgInfo(vsLegalCopyright);
icLegalTrades : GetPrgInfo(vsLegalTrades);
icOriginalFilename : GetPrgInfo(vsOriginalFilename);
icProductName : GetPrgInfo(vsProductName);
icComments : GetPrgInfo(vsComments);
end; { CASE }
GetLabelText := FVersionText;
end else GetLabelText := Name;
end;// -----------------------------------------------------------// Main version control functions
function GetVersionString;
var
zKeyPath : array[0..255] of char;
P : pointer;
{$IFDEF DELPHI_4}
Len : cardinal;
{$ELSE}
Len : integer;
{$ENDIF}
Language : string;
begin
Result := 'Unknown';
if not VerInfoPresent then Exit;
if VerQueryValue(Buf, StrPCopy(zKeyPath,
'\\VarFileInfo\\Translation'), P, Len) then
Language := format('%.8x', [SwapLong(Longint(P^))]);
if VerQueryValue(Buf, StrPCopy(zKeyPath,
'\\StringFileInfo\\'+Language+'\\'+AKey), P, Len) then
Result := StrPas(PChar(P));
end;function GetVersionDigits;
type PVerInfo = ^TVS_FIXEDFILEINFO;
var
zKeyPath : array[0..255] of Char;
{$IFDEF DELPHI_4}
Len : cardinal;
{$ELSE}
Len : integer;
{$ENDIF}
VerInfo : PVerInfo;
begin
Result := 'Unknown';
if not VerInfoPresent then Exit;
if VerQueryValue(Buf, StrPCopy(zKeyPath, '\'), pointer(VerInfo), Len) then
begin
if not AShort then
Result := IntToStr(HIWORD(VerInfo.dwFileVersionMS))+'.'+
IntToStr(LOWORD(VerInfo.dwFileVersionMS))+'.'+
IntToStr(HIWORD(VerInfo.dwFileVersionLS))+'.'+
IntToStr(LOWORD(VerInfo.dwFileVersionLS))
else Result := IntToStr(HIWORD(VerInfo.dwFileVersionMS))+'.'+
IntToStr(LOWORD(VerInfo.dwFileVersionMS));
end;
end;var
zSelfPath : array[0..255] of char;
{$IFDEF DELPHI_4}
L : cardinal;
{$ELSE}
L : integer;
{$ENDIF}
initialization
begin
VerInfoPresent := false;
Sz := GetFileVersionInfoSize(StrPCopy(zSelfPath, ParamStr(0)), L);
GetMem(Buf, Sz);
if (Sz > 0) and GetFileVersionInfo(StrPCopy(zSelfPath, ParamStr(0)), 0, Sz, Buf) then
VerInfoPresent := true;
end;finalization
begin
FreeMem(Buf, Sz);
end;
end.