首页 > 解决方案 > 通过注册表将子项添加到 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#winformsregistry

解决方案


推荐阅读