C# WPF应用程序没有';不能使用自己的注册表项

C# WPF应用程序没有';不能使用自己的注册表项,c#,visual-studio,regedit,registrykey,C#,Visual Studio,Regedit,Registrykey,我正在尝试在ContextMenu中添加经典的“使用MyApp发送” 事实上,我的程序修改了windows注册表,但似乎看不到它的更新版本。事实上,如果我重新启动程序,留下它修改过的键,它就可以正常工作 我如何解决这个问题(不创建另一个修改windows注册表的程序,然后调用我的) 提前谢谢你的帮助 附言。 下面是我用来修改注册表的函数 private void AddOption_ContextMenu() { RegistryKey _key1 = Registry.

我正在尝试在ContextMenu中添加经典的“使用MyApp发送”

事实上,我的程序修改了windows注册表,但似乎看不到它的更新版本。事实上,如果我重新启动程序,留下它修改过的键,它就可以正常工作

我如何解决这个问题(不创建另一个修改windows注册表的程序,然后调用我的)

提前谢谢你的帮助

附言。 下面是我用来修改注册表的函数

private void AddOption_ContextMenu()
    {
        RegistryKey _key1 = Registry.ClassesRoot.OpenSubKey("Folder\\shell", true);
        RegistryKey _key = Registry.ClassesRoot.OpenSubKey("*\\shell", true);

        RegistryKey newkey = _key.CreateSubKey("MyApp");
        RegistryKey newkey1 = _key1.CreateSubKey("MyApp");
        RegistryKey command = newkey.CreateSubKey("command");
        RegistryKey command1 = newkey1.CreateSubKey("command");
        string program = Path.GetDirectoryName(Application.ResourceAssembly.Location);

        for (int i = 0; i < 3; i++)
            program = Path.GetDirectoryName(program);

        program = @"""" + program + @"\\MyApp\\bin\\Debug\\MyApp.exe"" ""%1""";
        command.SetValue("", program);
        command1.SetValue("", program);
        newkey.SetValue("", "Send with MyApp");
        newkey.SetValue("Icon", Path.GetDirectoryName(Application.ResourceAssembly.Location) + "\\icon.ico");
        newkey1.SetValue("", "Send with MyApp");
        newkey1.SetValue("Icon", Path.GetDirectoryName(Application.ResourceAssembly.Location) + "\\icon.ico");

        command.Close();
        command1.Close();

        newkey1.Close();
        newkey.Close();
        _key.Close();
    }
    public void RemoveOption_ContextMenu()
    {
        RegistryKey _key = Registry.ClassesRoot.OpenSubKey("*\\shell", true);
        RegistryKey _key1 = Registry.ClassesRoot.OpenSubKey("Folder\\shell", true);
        _key.DeleteSubKeyTree("MyApp");
        _key1.DeleteSubKeyTree("MyApp");
        _key1.Close();
        _key.Close();
    }
private void AddOption_ContextMenu()
{
RegistryKey _key1=Registry.ClassesRoot.OpenSubKey(“Folder\\shell”,true);
RegistryKey _key=Registry.ClassesRoot.OpenSubKey(“*\\shell”,true);
RegistryKey newkey=_key.CreateSubKey(“MyApp”);
RegistryKey newkey1=_key1.CreateSubKey(“MyApp”);
RegistryKey命令=newkey.CreateSubKey(“命令”);
RegistryKey command1=newkey1.CreateSubKey(“命令”);
string program=Path.GetDirectoryName(Application.resourceSassembly.Location);
对于(int i=0;i<3;i++)
program=Path.GetDirectoryName(程序);
程序=@“”+程序+@“\\MyApp\\bin\\Debug\\MyApp.exe”“%1”“;
命令设置值(“,程序);
command1.SetValue(“,程序);
newkey.SetValue(“,“使用MyApp发送”);
newkey.SetValue(“Icon”,Path.GetDirectoryName(Application.resourceSassembly.Location)+“\\Icon.ico”);
newkey1.SetValue(“,“使用MyApp发送”);
newkey1.SetValue(“Icon”,Path.GetDirectoryName(Application.resourceSassembly.Location)+“\\Icon.ico”);
command.Close();
command1.Close();
newkey1.Close();
newkey.Close();
_key.Close();
}
public void RemoveOption_ContextMenu()
{
RegistryKey _key=Registry.ClassesRoot.OpenSubKey(“*\\shell”,true);
RegistryKey _key1=Registry.ClassesRoot.OpenSubKey(“Folder\\shell”,true);
_key.DeleteSubKeyTree(“MyApp”);
_关键字1.删除子关键字树(“MyApp”);
_键1.Close();
_key.Close();
}

你读过这个吗?

我在几年前发现了这个问题,我认为必须(至少)使用两个不同的C#线程来查看注册表项-->

参考:

您所说的“它看不到它的更新版本”是什么意思?您在哪里读取创建的注册表项?顺便说一句:您忘记在第一个方法中关闭_key1。我建议改用
using(RegistryKey=…)
。如果我在应用程序启动后打开“regedit”,我可以看到修改过的键,它们可以工作,但前提是我关闭程序并重新运行它而不修改注册表中的任何内容。如果这听起来很奇怪,我很抱歉,但我不知道如何以不同的方式解释。我仍然不明白你所说的“它看不到它的更新版本”是什么意思。在您提供的代码中,您只修改注册表,而不读取它。那么“see”是什么意思呢?程序修改注册表。然后,当它运行时,我点击一个文件的上下文菜单,我可以看到“用MyApp发送”选项,但它不起作用。“它看不到它的更新版本”是个人的观点,基于这样一个事实:如果我关闭并重新启动程序(这次没有修改注册表中的任何内容),它工作正常。不,写入注册表会立即生效。只有当你的应用程序或组件使用缓存注册表值时,这些值才需要刷新。阅读此问题时,我认为Luca希望读取在调试中修改的注册表项,但这与缓存的启动条件不同。谢谢GCiandro,我有机会对其进行测试,在注册表中有一个专门的更改线程,它可以完美地工作。