Adding and removing a shell extension.  

The following code shows you how to add and remove a shell extension in Delphi. This code was taken from borland.public.delphi.winapi, written by Erik Turner.

See also:   Shell namespace information

 


 
{ Add shell extension to registry }
procedure AddShellExt(const GUID: TGUID;
                      const ShellExtDll, FileExt, UtilityName: string);
var Key: string;
    BufGUID: array [0..255] of WideChar;
    FileType: string;
begin
  with TRegistry.Create do
  try
    RootKey := HKEY_CLASSES_ROOT;
    StringFromGUID2(GUID, BufGUID, SizeOf(BufGUID));
 
    if not OpenKey(FileExt, False) then Exit;
 
    if FileExt <> '*' then
    begin
      FileType := ReadString('');
      CloseKey;
      OpenKey(FileType, False);
    end;
 
    Key := Format('shellex\ContextMenuHandlers\%s', [UtilityName]);
    OpenKey(Key, TRUE);
    WriteString('', BufGUID);
    CloseKey;
 
    Key := Format('CLSID\%s', [BufGUID]);
    OpenKey(Key, True);
    WriteString('', UtilityName);
    OpenKey('InprocServer32', True);
    WriteString('', ShellExtDll);
    WriteString('ThreadingModel', 'Apartment');
    CloseKey;
  finally
    Free;
  end; {try}
end;
 
 
{ Remove shell extension from registry }
procedure RemoveShellExt(const GUID: TGUID;
                         const ShellExtDll, FileExt, UtilityName: string);
var Key: string;
    BufGUID: array [0..255] of WideChar;
    FileType: string;
begin
  with TRegistry.Create do
  try
    RootKey := HKEY_CLASSES_ROOT;
    StringFromGUID2(GUID, BufGUID, SizeOf(BufGUID));

    FileType := FileExt;
    if FileType <> '*' then
    begin
      if not OpenKey(FileExt, False) then Exit;
      FileType := ReadString('');
      CloseKey;
    end;
 
    Key := Format('%s\shellex\ContextMenuHandlers\%s', [FileType,UtilityName]);
    DeleteKey(Key);

    Key := Format('CLSID\%s', [BufGUID]);
    DeleteKey(Key);
  finally
    Free;
  end; {try}
end;
 
 
Return to the main page


This page was created by Ashley Godfrey, 1998.
Borland Delphi is a registered trademark of Inprise Corporation
Window's 95 and Internet Explorer are registered trademarks of Microsoft Corporation
All other products and logos are the property of theor respective owners
Inprise Corporation is in no way affiliated with Ashley Godfrey, this site or any of his software.