5,386
社区成员
发帖
与我相关
我的任务
分享
procedure GetVersionInfo(FFilePath: string);
const
SNotAvailable = 'Value Not Available';
var
LanguageID: string;
CodePage: string;
TranslationLength: Cardinal;
TranslationTable: Pointer;
InfoSize, Temp, Len: DWord;
InfoBuf: Pointer;
CompanyName, FileDescription, FileVersion, InternalName, LegalCopyright: string;
LegalTradeMarks, OriginalFilename, ProductName, ProductVersion, Comments: string;
Value: PChar;
LookupString: string;
PathStz: array[ 0..MAX_PATH ] of Char;
begin
// Get File Version Information
if FFilePath = '' then
begin
GetModuleFileName( HInstance, PathStz, SizeOf( PathStz ) );
FFilePath := StrPas( PathStz );
end;
InfoSize := GetFileVersionInfoSize( PChar( FFilePath ), Temp );
if InfoSize > 0 then
begin
InfoBuf := AllocMem( InfoSize );
try
GetFileVersionInfo( PChar( FFilePath ), 0, InfoSize, InfoBuf );
if VerQueryValue( InfoBuf, '\VarFileInfo\Translation', TranslationTable, TranslationLength ) then
begin
CodePage := Format( '%.4x', [ HiWord( PLongInt( TranslationTable )^ ) ] );
LanguageID := Format( '%.4x', [ LoWord( PLongInt( TranslationTable )^ ) ] );
end;
LookupString := 'StringFileInfo\' + LanguageID + CodePage + '\';
if VerQueryValue( InfoBuf, PChar( LookupString + 'CompanyName' ), Pointer( Value ), Len ) then
CompanyName := Value;
if VerQueryValue( InfoBuf, PChar( LookupString + 'FileDescription' ), Pointer( Value ), Len ) then
FileDescription := Value;
if VerQueryValue( InfoBuf, PChar( LookupString + 'FileVersion' ), Pointer( Value ), Len ) then
FileVersion := Value;
if VerQueryValue( InfoBuf, PChar( LookupString + 'InternalName' ), Pointer( Value ), Len ) then
InternalName := Value;
if VerQueryValue( InfoBuf, PChar( LookupString + 'LegalCopyright' ), Pointer( Value ), Len ) then
LegalCopyright := Value;
if VerQueryValue( InfoBuf, PChar( LookupString + 'LegalTrademarks' ), Pointer( Value ), Len ) then
LegalTradeMarks := Value;
if VerQueryValue( InfoBuf, PChar( LookupString + 'OriginalFilename' ), Pointer( Value ), Len ) then
OriginalFilename := Value;
if VerQueryValue( InfoBuf, PChar( LookupString + 'ProductName' ), Pointer( Value ), Len ) then
ProductName := Value;
if VerQueryValue( InfoBuf, PChar( LookupString + 'ProductVersion' ), Pointer( Value ), Len ) then
ProductVersion := Value;
if VerQueryValue( InfoBuf, PChar( LookupString + 'Comments' ), Pointer( Value ), Len ) then
Comments := Value;
finally
FreeMem( InfoBuf, InfoSize );
end;
end
else
begin
CompanyName := SNotAvailable;
FileDescription := SNotAvailable;
FileVersion := SNotAvailable;
InternalName := SNotAvailable;
LegalCopyright := SNotAvailable;
LegalTrademarks := SNotAvailable;
OriginalFilename := SNotAvailable;
ProductName := SNotAvailable;
ProductVersion := SNotAvailable;
Comments := SNotAvailable;
end;
ShowMessage(CompanyName+ #13#10 + FileDescription + #13#10 + InternalName + #13#10 + FileVersion + #13#10 +
InternalName+#13#10 + LegalCopyright+#13#10 +LegalTrademarks+#13#10 +OriginalFilename+#13#10 +ProductName+#13#10
+ProductVersion+#13#10 +Comments);
end;