以下是一个小函数,用于判断注册表是否存在某项,但运行到某句时就报错,因为code的值为null,说明"H5895=;:"这个子键未找到,可是我用regedit查看过明明有啊,Why?
private bool IsRegeditExit(string name)
        {
            bool _exit = false;
            string[] subkeyNames;
            RegistryKey hkml = Registry.CurrentUser;
            RegistryKey software = hkml.OpenSubKey("Software", true);
            RegistryKey foxqd = software.OpenSubKey("foxqd", true);
            RegistryKey foxqdini = foxqd.OpenSubKey("foxqd.ini", true);
            RegistryKey code = foxqd.OpenSubKey("H5895=;:", true);
            subkeyNames = code.GetSubKeyNames();  //运行这句出错!
            foreach (string keyName in subkeyNames)
            {
                if (keyName == name)
                {
                    _exit = true;
                    return _exit;
                }
            }
            return _exit;
        }