Click here to Skip to main content
Licence 
First Posted 12 Apr 2005
Views 152,188
Bookmarked 117 times

Add a context menu to the Windows Explorer

By | 12 Apr 2005 | Article
Add a context menu to the Windows Explorer using Registry only.

Introduction

Many of us like the convenience of the context menus in Windows Explorer and hate typing long paths in the command prompt window. This tool is going to address this issue by adding a new item on the context menu when you right click on a folder. You could get a command prompt that will open in the parent directory and not elsewhere. If you are not interested in the command prompt, then you can specify another executable of your choice as the target and still save some clicks and typing.

Background

Dealing with Explorer usually requires some shell programming that is not always nice. Fortunately, the hack I'm going to describe would merely set some registry entries to make this happen.

Using the code

The registry entries are the following:

private const string MenuName = "Folder\\shell\\NewMenuOption";
private const string Command = "Folder\\shell\\NewMenuOption\\command";

The code is self-explanatory and it merely sets the registry:

private void btnAddMenu_Click(object sender, System.EventArgs e)
{
    RegistryKey regmenu = null;
    RegistryKey regcmd = null;
    try
    {
        regmenu = Registry.ClassesRoot.CreateSubKey(MenuName);
        if(regmenu != null)
            regmenu.SetValue("",this.txtName.Text);
        regcmd = Registry.ClassesRoot.CreateSubKey(Command);
        if(regcmd != null)
                regcmd.SetValue("",this.txtPath.Text);
    }
    catch(Exception ex)
    {
        MessageBox.Show(this,ex.ToString());
    }
    finally       
    {
        if(regmenu != null)
            regmenu.Close();
        if(regcmd != null)
            regcmd.Close();
    }        
}

Or it deletes the settings if you don't like them anymore:

private void btnRemoveMenu_Click(object sender, System.EventArgs e)
{
    try
    {
        RegistryKey reg = Registry.ClassesRoot.OpenSubKey(Command);
        if(reg != null)
        {
            reg.Close();
            Registry.ClassesRoot.DeleteSubKey(Command);
        }
        reg = Registry.ClassesRoot.OpenSubKey(MenuName);
        if(reg != null)
        {
            reg.Close();
            Registry.ClassesRoot.DeleteSubKey(MenuName);
        }
    }
    catch(Exception ex)
    {
        MessageBox.Show(this,ex.ToString());
    }
}

The rest of the code only provides a sane user interface.

Points of Interest

You obviously have all the rights to change the Registry for this application to run as desired.

History

  • 12th April, 2005 - version 1.0.0.0.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

dmihailescu

Software Developer (Senior)

United States United States

Member

Decebal Mihailescu is a software engineer with interest in .Net, C# and C++.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
AnswerRe: How can we link our exe file while right click the menu item Pinmemberdmihailescu12:56 12 Jan '10  
AnswerRe: How can we link our exe file while right click the menu item PinmemberTristanV23:06 14 Jun '10  
QuestionAdd Icon to the menu item Pinmembersk ghouse0:44 10 Sep '09  
GeneralAdd icon to the menu PinmemberMember 441027114:57 27 Apr '09  
Generaladding file,edit,view,help menus to an windows application Pinmemberaurosikhadas1:15 1 Oct '08  
GeneralIs it possible only windows xp and not 2000 Pinmemberhesaigo999ca3:38 24 Jul '08  
GeneralRe: Is it possible only windows xp and not 2000 Pinmemberdmihailescu12:52 24 Jul '08  
I've tested on XP only. Cry | :((
GeneralIt doesn't work for me [modified] PinmemberRoyce Fickling5:18 18 Jul '08  
GeneralRe: It doesn't work for me Pinmemberwrschmid5:18 20 Nov '08  
GeneralRe: It doesn't work for me PinmemberCodeMonkey853:25 3 Dec '08  
GeneralRe: It doesn't work for me Pinmemberdmihailescu13:08 3 Dec '08  
GeneralRe: It doesn't work for me PinmemberCodeMonkey8513:42 3 Dec '08  
QuestionIs it possible to added a menu hierarchy? Pinmembermaxx_delusional10:26 6 Jun '08  
AnswerRe: Is it possible to added a menu hierarchy? Pinmemberdmihailescu13:25 6 Jun '08  
GeneralRe: Is it possible to added a menu hierarchy? PinmemberGoran _11:43 2 Jul '08  
GeneralRegistry Entry throught Setup And Deployment Project PinmemberMohantaD6:57 23 Nov '07  
GeneralRe: Registry Entry throught Setup And Deployment Project Pinmemberdmihailescu13:27 6 Jun '08  
GeneralRe: Clicking on drive Pinmemberdae2200010:58 9 Oct '07  
Questioncontext menu in applications (notepad, word ..) [modified] Pinmemberbalu2340:11 19 Sep '07  
AnswerRe: context menu in applications (notepad, word ..) Pinmemberdmihailescu4:53 20 Sep '07  
QuestionRe: context menu in applications (notepad, word ..) Pinmemberbalu23418:52 20 Sep '07  
QuestionContext menu order Pinmembertwsabonrai3:50 19 Feb '07  
QuestionCommand arguments PinmemberMith-Randir3:49 26 Sep '06  
AnswerRe: Command arguments Pinmemberdmihailescu4:55 20 Sep '07  
GeneralRe: Command arguments PinmemberOnur Guzel5:02 15 Nov '10  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120604.1 | Last Updated 12 Apr 2005
Article Copyright 2005 by dmihailescu
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid