About the author
Raymond Chen wrote the original blog posts on enumerating all the programs that can launch a particular protocol and enumerating all the programs that can open a particular file extension.
I translated it to Delphi. The application below does 2 things: launching a web browser on Embarcadero and opening win.ini as a text file.
program
Handlers;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System
.
SysUtils,
Generics
Collections,
Winapi
ShlObj, System
Types, Winapi
ActiveX, idoc;
function
GetUIObjectOfFile(Handle: THandle;
const
Path:
string
;
RIID: TGUID;
var
P):
Boolean
ppidl, pidlChild: PItemIDList;
psfgaoOut: DWORD;
LShellFolder: IShellFolder;
begin
Result :=
False
if
Succeeded(SHParseDisplayName(
PChar
(Path),
nil
, ppidl,
0
, psfgaoOut))
then
Succeeded(SHBindToParent(ppidl, IID_IShellFolder,
Pointer
(LShellFolder), pidlChild))
Result := Succeeded(LShellFolder
GetUIObjectOf(Handle,
1
, pidlChild, RIID,
,
(P)));
end
CoTaskMemFree(ppidl);
LoadExtHandlers(
extension:
filter: ASSOC_FILTER): TList<IAssocHandler>
enumerator: IEnumAssocHandlers;
Fetched:
Cardinal
handler: IAssocHandler;
LName:
SHAssocEnumHandlers(
(extension), filter, enumerator);
repeat
Fetched :=
enumerator
Next(
, handler, Fetched);
Fetched<>
handler
GetName(LName);
WriteLn
(
'Handler: '
, LName);
not
Assigned(Result)
Result := TList
Create;
Result
Add(handler);
until
Fetched =
LoadProtocolHandlers(
protocol:
; filter: ASSOC_FILTER):
TList<IAssocHandler>;
AliasToEnumerator:
absolute enumerator;
SHAssocEnumHandlersForProtocolByApplication(
(protocol),
IID_IEnumAssocHandlers, AliasToEnumerator);
LProtocolHandlers, LExtHandlers: TList<IAssocHandler>;
LDataObject: IDataObject;
selection:
Integer
selection :=
LProtocolHandlers := LoadProtocolHandlers(
'http'
, ASSOC_FILTER_RECOMMENDED);
GetUIObjectOfFile(
'http://www.embarcadero.com'
, IID_IDataObject, LDataObject);
LProtocolHandlers[selection].Invoke(LDataObject);
LProtocolHandlers
Free;
LExtHandlers := LoadExtHandlers(
'.txt'
'C:\windows\win.ini'
LExtHandlers[selection].Invoke(LDataObject);
LExtHandlers