簡體   English   中英

WPF 應用程序無法使用自己的注冊表項

[英]WPF application doesn't work with its own registry key

我正在嘗試在 ContextMenu 中添加經典的“使用 MyApp 發送”。

事實是我的程序修改了windows注冊表,但是好像看不到它的更新版本。 事實上,如果我重新開始我的程序,留下它修改過的鍵,它就可以正常工作。

我該如何解決這個問題(不創建另一個修改 windows 注冊表然后調用我的程序)?

預先感謝您的幫助。

ps這里是我用來修改注冊表的函數

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();
    }

你試過讀這個嗎? 使用 C# 編輯了注冊表,但無法使用 regedit 找到更改

我幾年前發現了這個問題,我認為必須使用(至少)兩個不同的 C# 線程來查看注冊表項的更改 -->

ref: C#: 如何更改 windows 注冊表並立即生效

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM