Setting Shell Context Menu Icons


If you google something like “shell context menu icons”, I can almost guarantee that you won’t find much information on changing the icons in Windows Explorer’s right-click context menus. Actually, if you’re not afraid to edit your registry, it’s not that difficult to put icons on your own shortcut menu items, but the information on how to do it is a little scarce.

I don’t think this is Windows 7 specific, but the example I’m going to use is catered towards Windows 7 users. In Windows 7, if you use any of the “run command prompt here as administrator” examples floating around, you’re not likely to see the elevation icon appear in your context menu. This example shows how to add an elevated command prompt item to the context menu for right clicking the background of a folder, then two methods to put the elevation badge icon next to it. The second method can also be extended to put any icon you want next to a context menu item. For all instructions below, do not copy the quotes. Also, messing with your registry can mess up your computer. If you follow these instruction exactly, there shouldn’t be a problem, but if you don’t have a clue what you’re doing, backup your registry first.

To create the context menu item:

  1. Open regedit. Type “regedit” into the start menu and hit enter, or press Windows Key+R, type “regedit” and hit enter.
  2. Locate “HKEY_CLASSES_ROOT\Directory\Background\shell“. You should already see a key (the folders are keys) named “cmd” inside it.
  3. Right click “shell” and click on New->Key. Name it “runas”. By naming it “runas”, we tell Windows that this should be run as an administrator.
  4. Click on the new “runas” key, then on the right side of the window, double click on “(Default)”. Change the value to the text you want to appear in the context menu. Something like “Elevated command window” will work. Click OK.
  5. Right click in the right pane and choose New->String Value. Name it “NoWorkingDirectory”. You can leave the value blank.
  6. If you only want this to appear when you Shift+Right-Click to open the context menu, create another string value and name it “Extended”. Again, the value should be left blank.
  7. Right click again and choose New->Key. Name it “command”. This will be the command executed when you click the item.
  8. In the command key, double click on “(Default)” and change the value to cmd.exe /k pushd %V

To add the icon:

There are two ways to add the elevation badge icon. The first is probably the way you should do this, but the second will let you use any icon you want.

To add just the elevation badge icon, go to “HKEY_CLASSES_ROOT\Directory\Background\shell\runas” and create a new string value. Name it “HasLUAShield” and leave the value blank.

To add any icon you want, go to the same key and create a string value named “Icon”. Double click it and change its value to the path of the icon you want. Most default Windows icons are stored in either shell32.dll or imageres.dll inside the C:\Windows\system32 directory. You can use an icon inside a DLL by entering the path to the DLL followed by a comma, then the number of the icon. For DLLs in system folders like shell32.dll and imageres.dll, you don’t need the full path–just the name–so since the elevation badge is the 73rd icon in imageres.dll, enter “imageres.dll,73“. You can use a free tool called IconViewer to look at the icons stored inside DLLs and executables. I have not tried, but you can probably enter the path to a .ico file as well.

Cygwin: Override Command Here


Windows Vista introduced a nice little feature where Shift+Right Clicking the background in explorer added a “Open command window here” option. Unfortunately for us Cygwin users, this just opens cmd without running bash. Since you probably installed Cygwin for the unix shell, this is kinda annoying. But fear not. I have a hack.

Copy the following into a text file, change its extension to “.reg”, and run it. Make sure to change the path at the beginning if you have a different Cygwin directory. Now “Open command window here” will start the bash shell at the current directory.

Windows Registry Editor Version 5.00
@="c:\\cygwin\\bin\\bash.exe --login -i -c \"cd \\\"`cygpath -u '%V'`\\\";bash\""
@="c:\\cygwin\\bin\\bash.exe --login -i -c \"cd \\\"`cygpath -u '%V'`\\\";bash\""

For those of you who like regedit, here’s the same thing unescaped:

c:\cygwin\bin\bash.exe --login -i -c "cd \"`cygpath -u '%V'`\";bash"
c:\cygwin\bin\bash.exe --login -i -c "cd \"`cygpath -u '%V'`\";bash"

Have fun!