如何读取和写入LocalMachine注册表项

时间:2013-12-02 10:09:54

标签: c# registry

正在为我的应用程序开发一个visio插件,其中我有一个场景,用户点击按钮来更新驻留在LocalMachine中的注册表项。

RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\VisioAddIn",true);


            if (setting.Name == "abc")
            {
                Properties.Settings.Default[setting.Name] = txtbox1.Text;
                if (registryKey != null)
                    registryKey.SetValue("abc", (txtbox1.Text).ToString());
        registryKey.Close();
            }

            if (setting.Name == "def")
            {
                Properties.Settings.Default[setting.Name] = txtbox2.Text;
                if (registryKey != null)
                {
                    registryKey.SetValue("def", (txtbox2.Text).ToString());
                    registryKey.Close();
                }
            }

            Properties.Settings.Default.Save();

但是我收到以下错误System.UnAuthorisedAccessException:无法写入注册表项。

如果我在管理员模式下运行我的visio插件,则不会发生此错误。但它不是我的解决方案。请帮帮我。

哈里什

1 个答案:

答案 0 :(得分:-1)

我不想使用HKCU,因为它为所有用户保存(在我的情况下,用户会更多)。我找到了一个解决方案,我们可以提升UAC。

Link