List of supported protocol handlers

Please discuss general Delphi programming topics here.

List of supported protocol handlers

Postby Stefan » July 8th, 2011, 9:18 am

Hi,

Anyone know how I can get a list of all registered protocol handlers on a machine?
So just a list of what handlers (e.g. http, mailto, news, etc) are available to the system.
I'm not interested in registering my own or knowing what application is associated with the protocol, I just want the list of what has been registered.

Thanks
Stefan
User avatar
Stefan
Moderator
Moderator
 
Posts: 128
Joined: September 27th, 2004, 9:40 am
Location: Tilburg, The Netherlands

Re: List of supported protocol handlers

Postby Kambiz » July 8th, 2011, 8:44 pm

The following function fills a TString object with Name/Value pairs of protocol/description values.

If False passes as the CurrentUser parameter, only protocols registered for the current user will be listed. Otherwise, globally registered protocols will be retrieved. Therefore, to have all the protocols available to the user, you should call the function twice with different values for the CurrentUser parameter.

To make things easier, the function does not clear the list.

Code: Select all
uses
  Registry;

procedure FindUrlProtocols(List: TStrings; CurrentUser: Boolean);
var
  R: TRegistry;
  Keys: TStringList;
  MainKey, SubKey: String;
  I: Integer;
begin
  List.BeginUpdate;
  R := TRegistry.Create(KEY_QUERY_VALUE or KEY_ENUMERATE_SUB_KEYS);
  try
    if CurrentUser then
    begin
      R.RootKey := HKEY_CURRENT_USER;
      MainKey := '\Software\Classes';
    end
    else
    begin
      R.RootKey := HKEY_CLASSES_ROOT;
      MainKey := '\';
    end;
    Keys := TStringList.Create;
    try
      if R.OpenKeyReadOnly(MainKey) then
      begin
        R.GetKeyNames(Keys);
        R.CloseKey;
      end;
      for I := 0 to Keys.Count - 1 do
      begin
        SubKey := Keys[I];
        if (PChar(SubKey)^ <> '.') and R.OpenKeyReadOnly(MainKey + '\' + SubKey) then
        begin
          if R.ValueExists('URL Protocol') then
            List.Values[SubKey] := R.ReadString('');
          R.CloseKey;
        end;
      end;
    finally
      Keys.Free;
    end;
  finally
    R.Free;
  end;
  List.EndUpdate;
end;


Example of usage:
Code: Select all
ListBox1.Items.Clear;

 // Retrieve globally registered protocols
FindUrlProtocols(ListBox1.Items, False);

// Retrieve user protocols (user protocols have more precedence, so we overwrite the global ones)
FindUrlProtocols(ListBox1.Items, True);   
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: List of supported protocol handlers

Postby Stefan » July 11th, 2011, 11:43 am

Hi,

Thanks! Again...

If you're ever in Holland, let me know so I can arrange a job interview for you :)

Cheers,
Stefan
User avatar
Stefan
Moderator
Moderator
 
Posts: 128
Joined: September 27th, 2004, 9:40 am
Location: Tilburg, The Netherlands


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron