Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to return the windows right click items that is in HKEY_CLASSES_ROOT in order. By order like when you click a folder or a certain extension you get different menus and they are in separate places in HKEY_CLASSES_ROOT, how does windows know to return them in order on right click when they are in separate places? and so how could I?, using vs c# in my small project, also I can't find all of the menu items.

P.S: I'm a young hobby programmer and I don't know much about win shell/script, it would be nice if you could explain briefly or link a topic about this.

What I have tried:

Googling didn't help.
Cant find all the menu items got only these 2:

HKEY_CLASSES_ROOT\Folder\shell
HKEY_CLASSES_ROOT\Directory\shell
Posted
Updated 5-Sep-18 5:58am

If you do not know anything about this subject then I would suggest starting with a simpler project. You can find lots of useful tutorials in the https://www.codeproject.com/KB/shell/[^] section, or by using Google.
 
Share this answer
 
There is a good example of how to loop through all the keys for a registry here: https://stackoverflow.com/questions/1458653/iterate-through-registry-entries
Read about the Registry Key Class here: https://docs.microsoft.com/en-us/dotnet/api/microsoft.win32.registrykey?view=netframework-4.7.2

There are multiple keys that deal with the right-click context menu.
For file items:
HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\
Some additional menu items for programs are stored at these locations:
HKEY_CLASSES_ROOT\*\shell
HKEY_CLASSES_ROOT\AllFileSystemObjects\ShellEx\ContextMenuHandlers

For folder items:
HKEY_CLASSES_ROOT\Folder\shellex\ContextMenuHandlers\
HKEY_CLASSES_ROOT\Directory\shell

For desktop items:
HKEY_CLASSES_ROOT\Directory\Background\shell
HKEY_CLASSES_ROOT\Directory\Background\shellex\ContextMenuHandlers


It is a simple thing to get a key and loop over all the subkeys.
C#
using Microsoft.Win32;

        public void EnumerateRegistryKeys()
        {
            RegistryKey key = Registry.<desired root here>.OpenSubKey("<desired key here>");
            foreach (string subKeyName in key.GetSubKeyNames())
            {
                //Do something with subKeyName
            }
        }


In the above code you must substitute your desired root and key for the text in angle brackets. For example:
C#
RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"Folder\shellex\ContextMenuHandlers\");



NOTE: Reading the registry is pretty safe, but writing values to the registry can cause serious problems. Backup the registry before changing it.
 
Share this answer
 
v2
Comments
Thaana Paana 7-Sep-18 8:06am    
Sorry for the late reply, thanks this would be what I'm looking for, although I just delayed this project, I'm working on something else right now. Gonna break my keys and registry after this. Hopefully I won't mess my computer up

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900