这是我改写过的一个函数,你可以根据需要再修改修改:
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;