Click here to Skip to main content
Click here to Skip to main content

Add a context menu to the Windows Explorer

By , 12 Apr 2005
 

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

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 4memberBharat Mallapur12 Jul '12 - 15:22 
QuestionExplorer context menu seperatormemberMember 809151713 Feb '12 - 19:59 
QuestionIconmemberJrrS885 Dec '11 - 19:38 
GeneralMy vote of 3membermohammadrefaie4 Nov '11 - 7:14 
QuestionAdd a context menu to the Windows Explorer - Does not work for memembersubha@m9online30 Oct '11 - 22:08 
AnswerRe: Add a context menu to the Windows Explorer - Does not work for mememberfredthered27 Jan '12 - 2:41 
Questionhow can have add a customize item to right click windows 7 like winrar programmembersyasaketi19 Oct '11 - 19:34 
AnswerRe: how can have add a customize item to right click windows 7 like winrar programmemberdmihailescu20 Oct '11 - 12:53 
GeneralMy vote of 1membersyasaketi19 Oct '11 - 19:32 
QuestionGreat - but ...memberWrangly4 Jul '11 - 21:08 
GeneralDrag DropmemberOnur Guzel15 Nov '10 - 4:10 
GeneralRe: Drag Dropmemberdmihailescu16 Nov '10 - 15:31 
GeneralRe: Drag DropmemberOnur Guzel19 Nov '10 - 8:58 
QuestionCan we add SuBemnumemberBassaammm12 Aug '10 - 2:21 
Generalfor VB.Netmemberphowarso13 May '10 - 20:01 
QuestionHow to retrieve the selected folder name?membergiji gangadharan17 Jan '10 - 19:42 
AnswerRe: How to retrieve the selected folder name?memberThomas Vogel26 Mar '10 - 6:11 
GeneralRe: How to retrieve the selected folder name?membermostafa.elsadany25 Jan '11 - 8:25 
GeneralRe: How to retrieve the selected folder name?membermostafa.elsadany25 Jan '11 - 8:36 
QuestionHow can we link our exe file while right click the menu itemmembergiji gangadharan11 Jan '10 - 21:44 
AnswerRe: How can we link our exe file while right click the menu itemmemberdmihailescu12 Jan '10 - 12:56 
AnswerRe: How can we link our exe file while right click the menu itemmemberTristanV14 Jun '10 - 23:06 
QuestionAdd Icon to the menu itemmembersk ghouse10 Sep '09 - 0:44 
GeneralAdd icon to the menumemberMember 441027127 Apr '09 - 14:57 
Generaladding file,edit,view,help menus to an windows applicationmemberaurosikhadas1 Oct '08 - 1:15 
GeneralIs it possible only windows xp and not 2000memberhesaigo999ca24 Jul '08 - 3:38 
GeneralRe: Is it possible only windows xp and not 2000memberdmihailescu24 Jul '08 - 12:52 
GeneralIt doesn't work for me [modified]memberRoyce Fickling18 Jul '08 - 5:18 
GeneralRe: It doesn't work for mememberwrschmid20 Nov '08 - 5:18 
GeneralRe: It doesn't work for mememberCodeMonkey853 Dec '08 - 3:25 
GeneralRe: It doesn't work for mememberdmihailescu3 Dec '08 - 13:08 
GeneralRe: It doesn't work for mememberCodeMonkey853 Dec '08 - 13:42 
QuestionIs it possible to added a menu hierarchy?membermaxx_delusional6 Jun '08 - 10:26 
AnswerRe: Is it possible to added a menu hierarchy?memberdmihailescu6 Jun '08 - 13:25 
GeneralRe: Is it possible to added a menu hierarchy?memberGoran _2 Jul '08 - 11:43 
GeneralRegistry Entry throught Setup And Deployment ProjectmemberMohantaD23 Nov '07 - 6:57 
GeneralRe: Registry Entry throught Setup And Deployment Projectmemberdmihailescu6 Jun '08 - 13:27 
GeneralRe: Clicking on drivememberdae220009 Oct '07 - 10:58 
Questioncontext menu in applications (notepad, word ..) [modified]memberbalu23419 Sep '07 - 0:11 
AnswerRe: context menu in applications (notepad, word ..)memberdmihailescu20 Sep '07 - 4:53 
QuestionRe: context menu in applications (notepad, word ..)memberbalu23420 Sep '07 - 18:52 
QuestionContext menu ordermembertwsabonrai19 Feb '07 - 3:50 
QuestionCommand argumentsmemberMith-Randir26 Sep '06 - 3:49 
AnswerRe: Command argumentsmemberdmihailescu20 Sep '07 - 4:55 
GeneralRe: Command argumentsmemberOnur Guzel15 Nov '10 - 5:02 
GeneralRe: Command argumentsmemberdmihailescu15 Nov '10 - 15:13 
Questionhow can i control in event handlermembersyriast31 Jul '06 - 1:05 
Questionget code in vb.netmembersyriast31 Jul '06 - 0:07 
AnswerRe: get code in vb.netmemberdmihailescu20 Sep '07 - 4:50 
QuestionHow do I set up the registry key value to allow for multiple file arguments?memberMartyP21 Apr '06 - 14:19 

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

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