Skip to content

Instantly share code, notes, and snippets.

@ILPlais
Created September 17, 2015 14:12
Show Gist options
  • Select an option

  • Save ILPlais/6912006624f37fd4ff8c to your computer and use it in GitHub Desktop.

Select an option

Save ILPlais/6912006624f37fd4ff8c to your computer and use it in GitHub Desktop.
Récupère des informations sur un exécutable
// Information sur un exécutable
TInfoSurExe = record
FileDescription,
CompanyName,
FileVersion,
InternalName,
LegalCopyright,
OriginalFileName,
ProductName,
ProductVersion: String;
end;
{***************************************************************************************}
// Récupère des informations sur un exécutable
function InfoSurExe(Fichier: String): TInfoSurExe;
const
VersionInfo: array [1..8] of String =
('FileDescription', 'CompanyName', 'FileVersion',
'InternalName', 'LegalCopyRight', 'OriginalFileName',
'ProductName', 'ProductVersion');
var
Handle: DWord;
Info: Pointer;
InfoData: Pointer;
InfoSize: Longint;
DataLen: UInt;
LangPtr: Pointer;
InfoType: String;
i: Integer;
begin
// Récupère la taille nécessaire pour les infos
InfoSize := GetFileVersionInfoSize(Pchar(Fichier), Handle);
// Initialise la variable de retour
with Result do
begin
FileDescription := '';
CompanyName := '';
FileVersion := '';
InternalName := '';
LegalCopyright := '';
OriginalFileName := '';
ProductName := '';
ProductVersion := '';
end;
i := 1;
// Si il y a des informations de version
if InfoSize > 0 then
begin
// Réserve la mémoire
GetMem(Info, InfoSize);
try
// Si les infos peuvent être récupérées
if GetFileVersionInfo(Pchar(Fichier), Handle, InfoSize, Info) then
repeat
// Spécifie le type d'information à récupérer
InfoType := VersionInfo[i];
if VerQueryValue(Info, '\VarFileInfo\Translation',
LangPtr, DataLen) then
InfoType := Format('\StringFileInfo\%0.4x%0.4x\%s'#0,
[LoWord(Longint(LangPtr^)), HiWord(Longint(LangPtr^)),
InfoType]);
// Remplit la variable de retour
if VerQueryValue(Info, @InfoType[1], InfoData, DataLen) then
case i of
1:
Result.FileDescription := StrPas(InfoData);
2:
Result.CompanyName := StrPas(InfoData);
3:
Result.FileVersion := StrPas(InfoData);
4:
Result.InternalName := StrPas(InfoData);
5:
Result.LegalCopyright := StrPas(InfoData);
6:
Result.OriginalFileName := StrPas(InfoData);
7:
Result.ProductName := StrPas(InfoData);
8:
Result.ProductVersion := StrPas(InfoData);
end;
// Incrémente i
Inc(i);
until i >= 8;
finally
// Libère la mémoire
FreeMem(Info, InfoSize);
end;
end;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment