c# - 通过注册表将子项添加到 Windows ContextMenu(无外壳)
问题描述
我想在 Windows 上下文菜单中添加一个菜单项,然后为所述菜单添加两个子菜单。我选择对文本文件进行测试,试图让两个子菜单都在记事本中打开文本文件,但不幸的是它不起作用。
我的菜单根本没有添加到上下文菜单中,我不知道是什么问题,因为所有注册表项都创建得很好。
我错过了什么?
PS:在 Windows 10 上进行测试,应用程序以管理员身份运行。
我按照本指南创建了我的代码。
using (RegistryKey key = Registry.ClassesRoot.OpenSubKey(".txt", true))
{
using (RegistryKey subkey = key.CreateSubKey(@"Shell\TestText"))
{
subkey.SetValue("MUIVerb", "TestText");
subkey.SetValue("SubCommands", "process1;process2");
subkey.SetValue("Icon", "notepad.exe");
using (RegistryKey localMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
{
using (RegistryKey shell = localMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell", true))
{
using (RegistryKey one = shell.CreateSubKey("process1"))
{
one.SetValue("", "Process 1");
one.CreateSubKey("command");
one.OpenSubKey("command", true).SetValue("", "notepad.exe \" % 1\"");
}
using (RegistryKey two = shell.CreateSubKey("process2"))
{
two.SetValue("", "Process 2");
two.CreateSubKey("command");
two.OpenSubKey("command", true).SetValue("", "notepad.exe \" % 1\"");
}
}
}
}
}
解决方案
推荐阅读
- c++ - 是否有任何 C++ 函数可以对哈希表进行排序?
- android - 启用 PRODUCT_FULL_TREBLE_OVERRIDE 标志会影响 SELINUX 策略吗?
- python - Xpath没有给出结果scrapy python
- php - soapclient 请求 https 服务器错误,“您正在对启用 SSL 的服务器端口使用纯 HTTP”
- javascript - 如何在 Yarn 工作区的一个 package.json 文件中安装包?
- java - Spring批处理JobExecutionListener不起作用
- azure-logic-apps - ISE 中的逻辑应用程序 - 事件触发器(存储)不会触发,而 ISE 外部的逻辑应用程序会针对同一事件触发
- c++ - 如何创建从另一个线程到 Qt5 GUI 线程的 qDebug 信号
- reactjs - 样式 react-slick.neostack
- git - GIT - 合并与复制到主分支之间的优势比较