Delphi - Programa associado à extensão


function PesquisaPrograma(const Ext: string): string;
var
  Reg: TRegistry;
begin
  Result := '';
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_CLASSES_ROOT;
  // chave de sistema
  if (Reg.OpenKey('.' + ext, False)) then begin
    Result := Reg.ReadString('');
    Reg.CloseKey;
    if (Result <> '') then begin
      // pesquisa chave de programa associado
      if reg.OpenKey(Result + '\Shell\Open\Command', False) then begin
        Result := Reg.ReadString('');
      end;
      Reg.CloseKey;
    end;
  end;
  // tira parâmetros da linha de comando
  if (Result <> '') and (Pos('%', Result) > 0)         then Delete(Result, Pos('%', Result), Length(Result));
  if (Result <> '') and (Result[1] = '"')              then Delete(Result, 1, 1);
  if (Result <> '') and (Result[Length(Result)] = '"') then Delete(Result, Length(Result), 1);
  while (Length(Result) > 0) and ((Result[Length(Result)] = ' ') or (Result[Length(Result)] = '"')) do begin
    Delete(Result, Length(Result), 1);
  end;

 

delphi · ‎registry · ‎funcao

Última atualização: 22/12/2017 às 16:43


  • Buscar