Question Windows right click Menu

This isn't necessarily a C# question or even a programming question. It's something that can be done manually in Windows:


You can, of course, write C# code to modify the Registry or have your app's installer do it.
 
Solution
This isn't necessarily a C# question or even a programming question. It's something that can be done manually in Windows:


You can, of course, write C# code to modify the Registry or have your app's installer do it.
wanted to run my application when user will right click any file using c#
 
That's what the '*' key in Classes key is for. To work with registry in C# see here: Microsoft.Win32 Namespace (in .Net Core add the Microsoft.Win32.Registry nuget package)
Note, HKCR is a merged view of the Software\Classes key from HKCU and HKLM, for writing to registry you should probably target HKCU.
 
Examples adding/removing the keys and values, the text shown in context menu is "My App".
C#:
public static void AddRegistry()
{
    using (RegistryKey my_app = Registry.CurrentUser.CreateSubKey(@"software\classes\*\shell\My App"),
                       command = my_app.CreateSubKey("command"))
    {
        my_app.SetValue("Extended", string.Empty); //only show in menu when Shift key is held
        var path = Process.GetCurrentProcess().MainModule.FileName;
        command.SetValue(string.Empty, $"{path} \"%1\"");
    }           
}

public static void RemoveRegistry()
{           
    Registry.CurrentUser.DeleteSubKeyTree(@"software\classes\*\shell\My App", false);
}
 
Back
Top Bottom