Buscar

Path de aplicativo associado a uma extensão

Código

Function GetExe(Ext : string) : string;
//
// Retorna o path completo do aplicativo que está associado
// ao arquivo cuja extensão você colocou em Ext
//
// Exemplo:
//
// Showmessage(GetExe('txt'));
// Vai retornar: C:WindowsNotepad.exe
//
var
reg: TRegistry; s : string;
I: integer;
begin
s := '';
reg := TRegistry.Create;
reg.RootKey := HKEY_CLASSES_ROOT;
if reg.OpenKey('.' + ext + 'shellopencommand',false) <> false then
  begin
  s := reg.ReadString('');
  reg.CloseKey;
  end
else
  begin
  if reg.OpenKey('.' + ext, false) <> false then
  begin
  s := reg.ReadString('');
  reg.CloseKey;
  if s <> '' then
  begin
  if reg.OpenKey(s + 'shellopencommand',false) <> false then
  begin
  s := reg.ReadString('');
  end;
  reg.CloseKey;
  end;
  end;
  end;
if ((length(s) > 0) and (s[1] = '"')) then
  Delete(s, 1, 1);
i := pos('.EXE',uppercase(S));
if I = 0 then
  begin
  Result := ''
  end
else
  begin
  Result := copy(S, 1, i +3);
  end;
end;

Publicidade

Vote na dica




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


Detalhes da dica

Categoria: Object pascal
Adicionada dia: 24/06/03
Por: Felipe Monteiro
Visualizada: 2068 vezes

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