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:
- Open regedit. Type “regedit” into the start menu and hit enter, or press Windows Key+R, type “regedit” and hit enter.
- Locate “
HKEY_CLASSES_ROOT\Directory\Background\shell“. You should already see a key (the folders are keys) named “cmd” inside it.
- 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.
- 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.
- Right click in the right pane and choose New->String Value. Name it “NoWorkingDirectory”. You can leave the value blank.
- 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.
- Right click again and choose New->Key. Name it “command”. This will be the command executed when you click the item.
- 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
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
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.
Great Post, really solved my problem…. Thanks
Perfectly Works on Windows 7 :)
But not in Windows XP :(
Unfortunately, I don’t have an XP system on hand, so I can’t test anything with XP.
Thanks for this post. It cleared up a couple of things for me, like the mysterious “HasLUAShield”.
I do have a question I’ve been unable to find an answer for, and I’m hoping you can help. Do you know of any way to create more than one elevated item in a single context menu (for example, an elevated “Open command window” prompt and an elevated “Take Ownership” prompt)? Is there a way to have more than one “runas”, or is there an alternative to “runas”?
Sorry for the late response. I don’t think there is a way to add more than one runas, but you might be able to use the elevate powertoy to achieve the same effect. For the “Take Ownership” command, you would just make a regular action, add HasLUAShield to it, and make the command
elevate "whatever the command to take ownership is"
I found the answer to my question about creating multiple runas keys in a single context menu: simply name the additional keys “runas(2)”, “runas(3)”, etc.
I didn’t know you could do that!