Mega Code Archive

 
Categories / Delphi / Files
 

File context menu entry for Explorer

Title: File context menu entry for Explorer Question: It is difficult to add an context entry to explorer, which pops up when user click with the mouse on a file. Usually this is done with com programming. A simple way to enter a single entry can be provided via registry. Answer: uses registry; procedure AddEntryToExplMenu(Adding:boolean); const DirExtensionKey = 'Directory\shell\encrypt'; FileExtensionKey = '*\shell\'; SubKey = '\command'; ContextName= 'Enter Context Name here'; IMPLEMENTATION {$R *.dfm} PROCEDURE TfmOptions.AddEntryToExplMenu(Adding:boolean); var reg: TRegistry; begin try reg := TRegistry.Create; except Exit; end; if Adding then with reg do begin RootKey := HKEY_CLASSES_ROOT; OpenKey(FileExtensionKey, Adding); WriteString('', ContextName); CloseKey; OpenKey(FileExtensionKey + ContextName+SubKey, Adding); WriteString('', ParamStr(0) + ' "%1"'); CloseKey; end else with reg do begin RootKey := HKEY_CLASSES_ROOT; DeleteKey(FileExtensionKey + ContextName); CloseKey; end; reg.Free; END;