Example #1
0
        public static void DeleteValue(RegistryRootKeys pRootKey, string pKeyPath, string valueName)
        {
            RegistryKey registryKey = RegistryAccess.GetRegistryRootKey(pRootKey).OpenSubKey(pKeyPath, true);

            if (registryKey == null)
            {
                throw new Exception(string.Format((IFormatProvider)CultureInfo.InvariantCulture, RegistryAccessStrings.DeleteValueError, (object)pKeyPath, (object)pRootKey.ToString()));
            }
            registryKey.DeleteValue(valueName, false);
        }
Example #2
0
        public static object ReadValue(RegistryRootKeys pRootKey, string pKeyPath, string pValueName, object pDefaultValue)
        {
            RegistryKey registryKey = RegistryAccess.GetRegistryRootKey(pRootKey).OpenSubKey(pKeyPath);
            object      obj         = pDefaultValue;

            if (registryKey != null)
            {
                obj = registryKey.GetValue(pValueName);
            }
            return(obj);
        }
Example #3
0
        public static void DeleteKey(RegistryRootKeys pRootKey, string pKeyPath)
        {
            int         length      = pKeyPath.LastIndexOf("\\");
            string      name        = pKeyPath.Substring(0, length);
            string      subkey      = pKeyPath.Substring(length + 1, pKeyPath.Length - length - 1);
            RegistryKey registryKey = RegistryAccess.GetRegistryRootKey(pRootKey).OpenSubKey(name, true);

            if (registryKey == null)
            {
                throw new Exception(string.Format((IFormatProvider)CultureInfo.InvariantCulture, RegistryAccessStrings.DeleteKeyError, (object)pKeyPath, (object)pRootKey.ToString()));
            }
            registryKey.DeleteSubKey(subkey);
        }
Example #4
0
        public static void WriteValue(RegistryRootKeys pRootKey, string pKeyPath, string valueName, object pValue, bool pCreateIfNotExist)
        {
            RegistryKey registryKey1 = RegistryAccess.GetRegistryRootKey(pRootKey);

            string[] strArray = pKeyPath.Split('\\');
            for (int index = 0; index < strArray.Length; ++index)
            {
                if (registryKey1 != null)
                {
                    RegistryKey registryKey2 = registryKey1.OpenSubKey(strArray[index], true);
                    if (registryKey2 == null & pCreateIfNotExist)
                    {
                        registryKey2 = registryKey1.CreateSubKey(strArray[index]);
                    }
                    registryKey1 = registryKey2;
                }
            }
            if (registryKey1 == null)
            {
                throw new Exception(string.Format((IFormatProvider)CultureInfo.InvariantCulture, RegistryAccessStrings.WriteValueError, (object)pKeyPath, (object)pRootKey.ToString()));
            }
            registryKey1.SetValue(valueName, pValue);
        }