![]() |
Languages »
C# »
Samples
Intermediate
Add a context menu to the Windows ExplorerBy dmihailescuAdd a context menu to the Windows Explorer using Registry only. |
C#.NET 1.0, .NET 1.1, .NET 2.0, Win2K, WinXPVS.NET2003, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||


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.
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.
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.
You obviously have all the rights to change the Registry for this application to run as desired.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 12 Apr 2005 Editor: Rinish Biju |
Copyright 2005 by dmihailescu Everything else Copyright © CodeProject, 1999-2009 Web19 | Advertise on the Code Project |