Monday, October 3, 2016

Add Program to Explorer Context Menu

 Hi in blog I am going to show to add a menu to explorer context menu by adding key to Registry using C#.In this i am going to add "Open in Browser" to the context menu whenever user right clicks on the txt file 'Open in Browser' Menu will show up and when user click the menu Firefox will be opened. 

Full Source Code:

    using Microsoft.Win32;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace AddProgramToContextMenu
    {
        class Program
        {                
            static void Main(string[] args)
            {
                try
                {
                    Program p = new Program();
                    p.AddValuestoRegistry();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error in Adding key to Registry value");
                }
            }

            public void AddValuestoRegistry()
            {
  RegistryKey regMenu = Registry.ClassesRoot.CreateSubKey("txtfile\\shell\\FileNameCatcher");
                regMenu.SetValue("", "Open in Browser");
                RegistryKey regCmd = Registry.ClassesRoot.CreateSubKey("txtfile\\shell\\FileNameCatcher\\command");
                regCmd.SetValue("",@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe");
                Console.WriteLine("Registry Modified Successfully...");
                Console.WriteLine("Press key to exit.");
                Console.ReadKey();
            }
        }
    }


Output:



Download:

Download Source Code




No comments:

Post a Comment