如何得知某一程序的版本、厂商及说明等内容?(100分)

  • 主题发起人 主题发起人 yansea
  • 开始时间 开始时间
Y

yansea

Unregistered / Unconfirmed
GUEST, unregistred user!
如题。
需要读注册表吗?或者其他,就象window里的系统信息得到的内容一样。
 
有人帮忙吗?
 
C中有一个stat的函数可以获取到一些有关文件的信息,但delphi中就不知道了。
 
查一下这几个函数的帮助就知道了, 主要是前3个
GetFileVersionInfoSize
GetFileVersionInfo
VerQueryValue

VerFindFile
VerInstallFile
VerLanguageName
 
有控件
http://www.pjsoft.contactbox.co.uk/
 
可以用 GetFileVersionInfo和VerQueryValue API函数将appliciton的版本信息编译进程序中,
调用例子如下:
procedure TForm1.Button1Click(Sender: TObject);

const
InfoNum = 10;
InfoStr: array[1..InfoNum] of string = ('CompanyName', 'FileDescription', 'FileVersion', 'InternalName', 'LegalCopyright', 'LegalTradeMarks', 'OriginalFileName', 'ProductName', 'ProductVersion', 'Comments');
var
S: string;
n, Len, i: DWORD;
Buf: PChar;
Value: PChar;
begin
S := Application.ExeName;
n := GetFileVersionInfoSize(PChar(S), n);
if n > 0 then
begin

Buf := AllocMem(n);
Memo1.Lines.Add('VersionInfoSize = ' + IntToStr(n));
GetFileVersionInfo(PChar(S), 0, n, Buf);
for i := 1 to InfoNum do
if VerQueryValue(Buf, PChar('StringFileInfo/040904E4/' + InfoStr, Pointer(Value), Len) then
Memo1.Lines.Add(InfoStr + ' = ' + Value);
FreeMem(Buf, n);
end
else
Memo1.Lines.Add('No version information found');
end;
 
这是我改写过的一个函数,你可以根据需要再修改修改:

procedure GetSoftInfo(var FInternalFileName, FLegalTrademarks, FCompanyName, FProductName, FProductVersion, FAuthor, FEmail: string); //得到程序的版本信息
type
TLANGANDCODEPAGE = record
wLanguage,
wCodePage: Word;
end;
PLANGANDCODEPAGE = ^TLANGANDCODEPAGE;
var
InfoResSize, // holds the size of the version info resource
Zero: DWORD; // a junk variable, its value is ignored
VersionInfo, // points to the version info resource
Info: Pointer; // a pointer to version information
Translation: PLANGANDCODEPAGE; // holds version info translation table
// FEmail,
// FAuthor,
FLanguage,
// FCompanyName,
// FProductVersion,
FFileDes,
FFileVersion,
// FInternalFileName,
FOriginalFilename,
FLegalCopyright,
// FLegalTrademarks,
// FProductName,
FComments: string;
VersionInfoSize: UINT; // holds the size of version information
//Filename,
InfoPath: string; // holds the version info request string

begin
//得到程序的版本信息

InfoResSize := GetFileVersionInfoSize(PChar(Application.ExeName), Zero);
if InfoResSize = 0 then exit;
//allocate the needed memory for the info structure
GetMem(VersionInfo, InfoResSize);
try
//Get the information of the current file
if not GetFileVersionInfo(PChar(Application.ExeName), 0, InfoResSize, VersionInfo) then
begin
FreeMem(VersionInfo);
exit;
end;

if VerQueryValue(VersionInfo, '/VarFileInfo/Translation', Pointer(Translation), VersionInfoSize) then
begin
//set the version value path string
InfoPath := '/StringFileInfo/' +
inttoHex(Translation^.wLanguage, 4) +
inttoHex(Translation^.wCodePage, 4) +
'/';

GetMem(Info, 2000);
VerLanguageName(Translation^.wLanguage, Info, 2000);
FLanguage := PChar(Info);
FreeMem(Info);
//Languages := VersionInfoSize div sizeof (TLANGANDCODEPAGE);
end
else //set default value
begin
//set the version value path string
InfoPath := '/StringFileInfo/040904E4/';
end;

//productname
if VerQueryValue(VersionInfo, PChar(InfoPath + 'ProductName'), Info, VersionInfoSize) then
FProductName := string(PChar(Info));

//get the company name
if VerQueryValue(VersionInfo, PChar(InfoPath + 'CompanyName'), Info, VersionInfoSize) then
FCompanyName := string(PChar(Info));

//productversion
if VerQueryValue(VersionInfo, PChar(InfoPath + 'ProductVersion'), Info, VersionInfoSize) then
FProductVersion := string(PChar(Info));

//legal Copyright
if VerQueryValue(VersionInfo, PChar(InfoPath + 'LegalCopyright'), Info, VersionInfoSize) then
FLegalCopyright := string(PChar(Info));

//legal trademarks
if VerQueryValue(VersionInfo, PChar(InfoPath + 'LegalTrademarks'), Info, VersionInfoSize) then
FLegalTrademarks := string(PChar(Info))
else
FLegalTrademarks := '';

//comments
if VerQueryValue(VersionInfo, PChar(InfoPath + 'Comments'), Info, VersionInfoSize) then
FComments := string(PChar(Info));

//original filename
if VerQueryValue(VersionInfo, PChar(InfoPath + 'OriginalFilename'), Info, VersionInfoSize) then
FOriginalFilename := string(PChar(Info));

//internal FileName
if VerQueryValue(VersionInfo, PChar(InfoPath + 'InternalName'), Info, VersionInfoSize) then
FInternalFileName := string(PChar(Info));

//get the file description
if VerQueryValue(VersionInfo, PChar(InfoPath + 'FileDescription'), Info, VersionInfoSize) then
FFileDes := string(PChar(Info));
//File Version
if VerQueryValue(VersionInfo, PChar(InfoPath + 'FileVersion'), Info, VersionInfoSize) then
FFileVersion := string(PChar(Info));
if VerQueryValue(VersionInfo, PChar(InfoPath + 'Author'), Info, VersionInfoSize) then
FAuthor := string(PChar(Info));
if VerQueryValue(VersionInfo, PChar(InfoPath + 'Email'), Info, VersionInfoSize) then
FEmail := string(PChar(Info));
finally
//free the memory
FreeMem(VersionInfo, InfoResSize);
end;
//====================================得到版本信息结束

end;
 
多谢个位,我试试看。
 
多人接受答案了。
 
后退
顶部