Answer:
It´s a simple function that retuns the iformation requested. You can use a VersionInfo array element to pass as the parameter:
Label1.Caption := GetFileInfo('c:\windows\explorer.exe', VersionInfo[3]);
or
Label1.Caption := GetFileInfo('c:\windows\explorer.exe', 'FileVersion');
===============================================
unit lFilever;
interface
uses
WinTypes, WinProcs, SysUtils {$IFNDEF WIN32} ,Ver {$ENDIF};
const
VersionInfo: array [1..8] of string = (
'CompanyName', 'FileDescription', 'FileVersion', 'InternalName',
'LegalCopyRight', 'OriginalFileName', 'ProductName', 'ProductVersion');
function GetFileInfo(FName, InfoType: string): string;
implementation
function GetFileInfo(FName, InfoType: string): string;
var
Info : Pointer;
InfoData : Pointer;
InfoSize : LongInt;
InfoLen : {$IFDEF WIN32} DWORD;{$ELSE} LongInt; {$ENDIF}
DataLen : {$IFDEF WIN32} UInt; {$ELSE} word; {$ENDIF}
LangPtr : Pointer;
begin
result:=''; DataLen:=255;
if Length(FName)<=0 then exit;
FName:=FName+#0;
InfoSize:=GetFileVersionInfoSize(@Fname[1], InfoLen);
if (InfoSize > 0) then
begin
GetMem(Info, InfoSize);
try
if GetFileVersionInfo(@FName[1], InfoLen, InfoSize, Info) then
begin
if VerQueryValue(Info,'\VarFileInfo\Translation',LangPtr, DataLen) then
InfoType:=Format('\StringFileInfo\%0.4x%0.4x\%s'#0,[LoWord(LongInt(LangPtr^)),
HiWord(LongInt(LangPtr^)), InfoType]);
if VerQueryValue(Info,@InfoType[1],InfoData,Datalen) then
Result := strPas(InfoData);
end;
finally
FreeMem(Info, InfoSize);
end;
end;
end;
end.
|