2011-11-04 59 views
1

我需要更改注册表中的子项。使用C修改注册表中的子项#

我GOOGLE了很多,并没有找到任何方法来更改子项。

微软是否支持此功能?

我能够改变的键/值对,但使用这种

Registry.SetValue(keypath, subkey, Guid.NewGuid().ToString("B")); 
+0

看这个问题:https://stackoverflow.com/questions/14170886/edit-registry-keys – boboes

回答

1

什么是你想改变的子项?如果是名称,则这是只读的,不能更改。 Regedit可以通过创建一个新密钥重新命名密钥,并单独将每个子密钥和值复制到新密钥。

0

如果您尝试更改“默认值”,请在设置时使用空白字符串作为值名称。

0
static void WriteRegistry(RegistryKey parentKey, String subKey, String valueName, Object value) 
{ 
     RegistryKey key; 
    try 
    { 
     key = parentKey.OpenSubKey(subKey, true); 
     if(key == null) //If the key doesn't exist. 
       { 
      key = parentKey.CreateSubKey(subKey); 
       } 

     //Set the value. 
     key.SetValue(valueName, value); 

     Console.WriteLine("Value:{0} for {1} is successfully written.", value, valueName); 
    } 
    catch(Exception e) 
    { 
     Console.WriteLine("Error occurs in WriteRegistry" + e.Message); 
    } 
} 
+0

这将创建一个子项。而我已经有一个子项,现在需要更改子项的名称/值。 –

+0

实际上,如果您查看代码,它只会创建一个子键,如果其中一个不存在,则检查OpenSubKey是否返回空值。 – ChrisBD