RegistryKey rsg = null;               //声明变量
 rsg = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\CrashControl", true); //true表可修改
                  if (rsg.GetValue("CrashDumpEnabled") != null)
                    {
                           rsg.SetValue("CrashDumpEnabled ", "2", RegistryValueKind.DWord);   //核心内存存储
                           rsg.Close();
                        MessageBox.Show("设置成功");
                    }
    为什么CrashDumpEnabled已存在,还会重新创建一个?

解决方案 »

  1.   

    RegistryValueKind.DWord类型设置的可能不对,你看看注册表里是什么类型的。
      

  2.   

    "CrashDumpEnabled "多了个空格。
      

  3.   


    //判断键值是否存在
    private bool IsRegeditKeyExit()    
    {    
    string[] subkeyNames;    
    RegistryKey hkml = Registry.LocalMachine;    
    RegistryKey software = hkml.OpenSubKey(SOFTWAREtest);    
    RegistryKey software = hkml.OpenSubKey(SOFTWAREtest, true);    
    subkeyNames = software.GetValueNames();    
    //取得该项下所有键值的名称的序列,并传递给预定的数组中    
    foreach (string keyName in subkeyNames)    
    {    
    if (keyName == test) 判断键值的名称    
    {    
    hkml.Close();    
    return true;    
    }    
    }    
    hkml.Close();    
    return false;    
    }   
      

  4.   

    rsg.SetValue("CrashDumpEnabled", 2, RegistryValueKind.DWord); 是不是这样呢?