Apr
25
Определить WebBrowser по умолчанию 2
14:15uses
Registry;
function StripChar(SelChar: Char; PassedStr: STRING): STRING;
var
DelPos: Integer;
begin
while Pos(SelChar, PassedStr) <> 0 do
begin
DelPos := Pos(SelChar, PassedStr);
Delete(PassedStr, DelPos, SizeOf(SelChar));
end;
Result := PassedStr;
end;
function GetDefaultBrowser: STRING;
var
Reg: TRegistry;
RegKeyInfo: TRegKeyInfo;
HtmlKey, AssocType, FullProgPath: String;
DelPos, DelLength: Integer;
begin
Reg := TRegistry.Create;
try
try
HtmlKey := '.HTML';
Reg.RootKey := HKEY_CLASSES_ROOT;
if (Reg.KeyExists(HtmlKey)) then
begin
if Reg.OpenKey(HtmlKey, FALSE) then
begin
AssocType := Reg.ReadString('');
Reg.CloseKey;
AssocType := AssocType + '\SHELL\OPEN\COMMAND';
if Reg.OpenKey(AssocType, FALSE) then
begin
FullProgPath := UpperCase(Reg.ReadString(''));
FullProgPath:= StripChar('"', FullProgPath);
DelPos := Pos('EXE', FullProgPath);
DelLength := Length(FullProgPath) - DelPos;
if DelPos <> 0 then
Delete(FullProgPath, DelPos+3, DelLength+1);
Result := FullProgPath;
Reg.CloseKey;
end;
end;
end
else
Result := 'Не удалось обнаружить веб-браузер по умолчанию.';
except
Result := 'Не удалось обнаружить веб-браузер по умолчанию.';
end; { try/except }
finally
Reg.Free;
end; { try/finally }
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage( GetDefaultBrowser);
end;