Buscar

Pega informações de versão de qualquer exe ou dll

Código

Function GetFileVersion(const FileName: string; var Major, Minor, Release, Build: Integer): Boolean;
// by AcidBytes - acidbytes@ig.com.br
//     icq 63912484
// English
// get Major, Minor, Release, Build for an EXE or DLL file.
// returns true=success.
// returns false=failure-probably info not found in the file.

// Portugues
//  Pega os números de versão maior, Menor, release e build para o arquivo
//       exe ou dll passado como argumento em FileName, coloca esses números
//       nas variáveis major, minor, release e build passadas como referencia.
// Retorna True = Sucesso, conseguiu obter a versão
// Retorna False = Falha, provavelmente arquivo não localizado ou informação
//                 de versão não consta no arquivo.

var
  Zero: DWORD; // set to 0 by GetFileVersionInfoSize
  VersionInfoSize: DWORD;
  PVersionData: pointer;
  PFixedFileInfo: PVSFixedFileInfo;
  FixedFileInfoLength: UINT;

begin
  Result := False;
  Major := 0;
  Minor := 0;
  Release := 0;
  Build := 0;
  VersionInfoSize := GetFileVersionInfoSize(pChar(FileName), Zero);
  if VersionInfoSize = 0 then
     exit;
  PVersionData := AllocMem(VersionInfoSize);
  try
    if GetFileVersionInfo(pChar(FileName), 0, VersionInfoSize, PVersionData) = False then
       exit;
//      raise Exception.Create('Não pude recuperar informação sobre versão');
    if VerQueryValue(PVersionData, '', pointer(PFixedFileInfo), FixedFileInfoLength) = False then
       exit;
    Major := PFixedFileInfo^.dwFileVersionMS shr 16;
    Minor := PFixedFileInfo^.dwFileVersionMS and $FFFF;
    Release := PFixedFileInfo^.dwFileVersionLS shr 16;
    Build := PFixedFileInfo^.dwFileVersionLS and $FFFF;
  finally
    FreeMem(PVersionData);
  end;
  if (Major or Minor or Release or Build) <> 0 then
     result := True;
//    result := IntToStr(Major) + IntToStr(Minor) + IntToStr(Release) + IntToStr(Build);
end;
 

Publicidade

Vote na dica




Quantidade de votos: 0 votos
Aceitação: 0%


Detalhes da dica

Categoria: Windows
Adicionada dia: 26/07/03
Por: Amilton Maciel
Visualizada: 11498 vezes

Planeta Delphi - Tudo sobre programação Delphi Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009