使用C#按顺序获取Windows右键单击项目 [英] Get windows right click items in order using C#

查看:125
本文介绍了使用C#按顺序获取Windows右键单击项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想按顺序返回窗口右键单击HKEY_CLASSES_ROOT中的项目。通过顺序,例如当您单击文件夹或某个扩展名时,您获得了不同的菜单,并且它们位于HKEY_CLASSES_ROOT的不同位置,当Windows处于不同的位置时,Windows如何知道按顺序返回它们?我怎么可能?在我的小项目中使用vs c#,我也找不到所有的菜单项。



PS:我还年轻爱好程序员,我不太了解win shell / script,如果你能简单解释或链接一个关于这个的话题会很好。



我尝试了什么:



谷歌搜索没有帮助。

无法找到所有菜单项只有这两个:



HKEY_CLASSES_ROOT\Folder\shell

HKEY_CLASSES_ROOT \Directory\shell

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

推荐答案

如果您对此主题一无所知,那么我建议从一个更简单的项目开始。您可以在 https://www.codeproject.com/KB/shell/ 中找到许多有用的教程[< a href =https://www.codeproject.com/KB/shell/target =_ blanktitle =New Window> ^ ]部分,或者使用Google。
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.


这里有一个很好的示例,说明如何遍历注册表的所有密钥: https ://stackoverflow.com/questions/1458653/iterate-through-registry-entries

在此处阅读注册表项类: https://docs.microsoft.com/en-us/dotnet/api/microsoft.win32.registrykey? view = netframework-4.7.2



有多个键处理右键单击上下文菜单。

For文件:

HKEY_CLASSES_ROOT \ * \ shellex \ContextMenuHandlers \

S程序的其他菜单项存储在以下位置:

HKEY_CLASSES_ROOT \ * \ shell

HKEY_CLASSES_ROOT \ AllFileSystemObjects\ShellEx\ContextMenuHandlers



对于文件夹项目:

HKEY_CLASSES_ROOT \Folder\shellex\ContextMenuHandlers \

HKEY_CLASSES_ROOT \Directory \ shell



对于桌面商品:

HKEY_CLASSES_ROOT \Directory \ Background\shell

HKEY_CLASSES_ROOT \Directory \ Background\shellex \ContextMenuHandlers





获取密钥并遍历所有子密钥是一件简单的事。

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.
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:

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.


这篇关于使用C#按顺序获取Windows右键单击项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆