无法在注册表中创建子项

时间:2016-03-17 18:54:17

标签: c# registry

以下代码运行时没有错误,但有异常。但是,未创建子项。不确定是什么问题。谢谢!

try
{
    var stupPath = "\"" + folder + "\\My.exe\" \"currentuser\"  \"" + folder + "\"";
    var subkeyHKLM = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Active Setup\Installed Components", true);
    if (subkeyHKLM == null) return;
    subkeyHKLM.CreateSubKey("MyAddIn");
    subkeyHKLM.SetValue("StubPath", stupPath, RegistryValueKind.ExpandString);
    subkeyHKLM.Close();
}
catch (Exception ex)
{
}

更新

我更改为以下内容现在可以正常工作,但密钥是在HKLM \ Software \ Wow6432Node \ Microsoft \ Active Setup \ Installed Components

中创建的
            var newKey = subkeyHKLM.CreateSubKey("MyAddIn");
            if (newKey != null)
            {
                newKey.SetValue("StubPath", stupPath, RegistryValueKind.ExpandString);
            }
            subkeyHKLM.Close();

0 个答案:

没有答案