vaishalimaha
New member
- Joined
- Feb 7, 2021
- Messages
- 3
- Programming Experience
- Beginner
How to Add application executable file in windows right click menu?
wanted to run my application when user will right click any file using c#This isn't necessarily a C# question or even a programming question. It's something that can be done manually in Windows:
![]()
How to Add Any Application Shortcut to Windows Explorer's Context Menu
With a quick registry tweak, you can add any application to any Windows Explorer context menu.www.howtogeek.com
You can, of course, write C# code to modify the Registry or have your app's installer do it.
Thank you .I will tryThat'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.
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);
}