We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

how to add an option in the right click menu

manganzon
manganzon asked
on
Medium Priority
169 Views
Last Modified: 2010-04-05
hello, i have a program that encrypt a file u select (with opendialog1)  but i would like to add an option to the explorer menu u get when u right click a file or folder.
i found this already:

procedure TForm1.Button1Click(Sender: TObject);  
procedure InstalaMenuContextual( Extension,Comando,CaptionMenu  :string);
   var
     Registro : TRegistry;
     Nombre   : string;
   begin
     Registro := TRegistry.Create;
     try
       Registro.RootKey := HKEY_CLASSES_ROOT;
       if Registro.OpenKeyReadOnly('\.' + Extension) then
       begin
         Nombre := Registro.ReadString('');
         if Nombre <> '' then
           if Registro.OpenKey('\' + Nombre + '\shell', False) then
             Registro.Access := KEY_READ or KEY_WRITE;
         if Registro.OpenKey('APTprocess', True) then
         begin
           Registro.WriteString('', CaptionMenu);
           Registro.Access := KEY_READ or KEY_WRITE;
           if Registro.OpenKey('command', True) then
             Registro.WriteString('','"'+Comando+'" "%1"');
         end;
       end else Raise Exception.create('Lo siento, la extension no es conocida por Windows');
     finally
       Registro.Free;
     end;
   end;

begin

   InstalaMenuContextual( 'TST',
                          Application.ExeName,
                          'blabla');
end;

but this only will work for that extension, not for all files and of course it only calls my program, i also need my program to handle the files selected automatically.
i need to encrypt those files i select, so i would need my program to take those parameters.
like an antivirus software, u choose a bunch of files then click the option in the right click menu and it scans all the files u selected.
and if a folder is selected, it will encrypt all files in the folder.
just like an antivirus would do.

so ill be waiting for some code or hints.
Comment
Watch Question

This will register for all file types,

procedure RegisterMenu;
var
  Reg:TRegistry;
begin
  Reg:= TRegistry.Create;
  Reg.RootKey := HKEY_CLASSES_ROOT;
  Reg.OpenKey('*\shell\Program...\command', True);
  Reg.WriteString('', '"'+ParamStr(0)+'" "%1"');
  Reg.Free;
end;

procedure UnRegisterMenu;
var
  Reg:TRegistry;
begin
  Reg:= TRegistry.Create;
  Reg.RootKey := HKEY_CLASSES_ROOT;
  Reg.OpenKey('*\shell', true);
  Reg.DeleteKey('Program...');
  Reg.Free;
end;

But note, If you select multiple files then use the explorer menu, explorer will open your program for each file selected.

have a look at contmenu.dpr in the Program Files\Borland\Delphi\Demos\ActiveX\ShellExt folder. Thats a better way to make an explorer menu.

Commented:
i think this could help you: http://windowsxp.mvps.org/context_folders.htm

Author

Commented:
sorry, i got busy with another project but anyway, the main problem is to handle the files u select before u click on the explorer button.
so if i have a function: encrypt(file);
it will just use that function to deal with all the files that were selected in explorer before my application was called.
how can get the name(s) of the file(s) selected in order to process them afterwards.

Commented:
you should  check the params of your app and execute function according to the params..

let assume your app name is ENCRYPT.exe the params may look like this
c\>ENCRYPT.exe -e somefile.txt

paramstr[0] is your app name {ENCRYPT.exe}
paramstr[1] is the parameter for encryption {-e}
paramstr[2] is the filename {somefile.txt}

just from mind...try it

Author

Commented:
yea i already knew i had to use paramstr(1) for the file to be encrypted, but what if there are many files selected?
Commented:
windows will treat each selected file as it is the only one selected.... and run you program as many times as the number of the selected files...so make you program to prevent more than one instance....then you'll see all the selected files opened in one instance....

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
good enough.
:D

Commented:
;-)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.