1

I have already successfully created a context menu which allow users to process any type of files by my program, but when a user to select more than 1 file then click the context menu item, my program would be called and run for several times. How to make context menu to open multiple files in one process in C# Winform program? By the way the program has to be run as Administrator, and I have already set a manifest file for it.

Code:

try
{
    RegistryKey _key = Registry.ClassesRoot.OpenSubKey("Folder\\Shell", true);
    RegistryKey newkey = _key.CreateSubKey("MyProgram");
    newkey.SetValue("Icon", Application.ExecutablePath);

    RegistryKey subNewkey = newkey.CreateSubKey("Command");
    subNewkey.SetValue("", Application.ExecutablePath + " \"%1\"");
    subNewkey.Close();

    newkey.Close();
    _key.Close();
}
catch
{ }

try
{
    RegistryKey _key = Registry.ClassesRoot.OpenSubKey("*\\Shell", true);
    RegistryKey newkey = _key.CreateSubKey("MyProgram");
    newkey.SetValue("Icon", Application.ExecutablePath);

    RegistryKey subNewkey = newkey.CreateSubKey("Command");
    subNewkey.SetValue("", Application.ExecutablePath + " \"%1\"");
    subNewkey.Close();

    newkey.Close();
    _key.Close();
}
catch
{ }
Genusatplay
  • 761
  • 1
  • 4
  • 15
SuperBerry
  • 1,193
  • 1
  • 12
  • 28
  • Related but in VB.Net: https://stackoverflow.com/questions/2703856/open-program-once-with-multiple-files-as-arguments-from-explorer – rene Sep 18 '21 at 09:31
  • or this one: https://stackoverflow.com/questions/27088510/implement-explorer-contextmenu-and-pass-multiple-files-to-one-program-instance?rq=1 – rene Sep 18 '21 at 09:39

0 Answers0