public static void WriteValue(RegistryRootKeys rootKey, string keyPath,
                                      string valueName, object value, bool createIfNotExist)
        {
            RegistryKey regKey = GetRegistryRootKey(rootKey);

            string[]    pathToken = keyPath.Split('\\');
            RegistryKey subKey    = null;

            for (int i = 0; i < pathToken.Length; i++)
            {
                if (regKey != null)
                {
                    subKey = regKey.OpenSubKey(pathToken[i], true);
                    if (subKey == null && createIfNotExist)
                    {
                        subKey = regKey.CreateSubKey(pathToken[i]);
                    }
                    regKey = subKey;
                }
            }
            if (regKey != null)
            {
                regKey.SetValue(valueName, value);
            }
            else
            {
                throw new ApplicationException("Cannot create " + rootKey.ToString() + "\\" + keyPath);
            }
        }
 public static void WriteValue(RegistryRootKeys rootKey, string keyPath,
     string valueName, object value, bool createIfNotExist)
 {
     RegistryKey regKey = GetRegistryRootKey(rootKey);
     string[] pathToken = keyPath.Split('\\');
     RegistryKey subKey = null;
     for (int i = 0; i < pathToken.Length; i++)
     {
         if (regKey != null)
         {
             subKey = regKey.OpenSubKey(pathToken[i], true);
             if (subKey == null && createIfNotExist)
             {
                 subKey = regKey.CreateSubKey(pathToken[i]);
             }
             regKey = subKey;
         }
     }
     if (regKey != null)
     {
         regKey.SetValue(valueName, value);
     }
     else
     {
         throw new ApplicationException("Cannot create " + rootKey.ToString() + "\\" + keyPath);
     }
 }
Example #3
0
        /* Methode zum Löschen eines Schlüssels in der Registry */
        public static void DeleteKey(RegistryRootKeys rootKey, string keyPath)
        {
            // Den Pfad zum übergeordneten Schlüssel und den Namen des zu löschenden
            // Schlüssels ermitteln
            int    i             = keyPath.LastIndexOf("\\");
            string parentKeyPath = keyPath.Substring(0, i);
            string keyName       = keyPath.Substring(i + 1, keyPath.Length - i - 1);

            // Den dem zu löschenden Schlüssel übergeordneten Schlüssel zum Schreiben
            // öffnen
            RegistryKey regKey = GetRegistryRootKey(rootKey).OpenSubKey(
                parentKeyPath, true);

            if (regKey != null)
            {
                // Schlüssel über den übergeordneten Schlüssel löschen
                regKey.DeleteSubKey(keyName);
            }
            else
            {
                // Schlüssel nicht gefunden: Ausnahme werfen
                throw new Exception("Schlüssel " + rootKey.ToString() + "\\" +
                                    keyPath + " nicht gefunden");
            }
        }
Example #4
0
        /* Methode zum Löschen eines Werts in der Registry */
        public static void DeleteValue(RegistryRootKeys rootKey, string keyPath,
                                       string valueName)
        {
            // Unterschlüssel zum Schreiben öffnen
            RegistryKey regKey = GetRegistryRootKey(rootKey).OpenSubKey(
                keyPath, true);

            // Wert über den übergeordneten Schlüssel löschen
            // wenn dieser gefunden wurde
            if (regKey != null)
            {
                regKey.DeleteValue(valueName, false);
            }
            else
            {
                // Schlüssel nicht gefunden: Ausnahme werfen
                throw new Exception("Schlüssel " + rootKey.ToString() + "\\" +
                                    keyPath + " nicht gefunden");
            }
        }
Example #5
0
        /*  Methode zum Schreiben eines Registry-Eintrags */
        public static void WriteValue(RegistryRootKeys rootKey, string keyPath,
                                      string valueName, object value, bool createIfNotExist)
        {
            // Wurzel-Schlüssel ermitteln
            RegistryKey regKey = GetRegistryRootKey(rootKey);

            // Den Pfad in seine Einzelteile zerlegen
            string[] pathToken = keyPath.Split('\\');

            // Pfad durchgehen und den Schlüssel referenzieren
            RegistryKey subKey = null;

            for (int i = 0; i < pathToken.Length; i++)
            {
                if (regKey != null)
                {
                    // Unterschlüssel zum Lesen und Schreiben öffnen
                    subKey = regKey.OpenSubKey(pathToken[i], true);

                    if (subKey == null && createIfNotExist)
                    {
                        // Unterschlüssel nicht gefunden: Schlüssel erzeugen
                        // falls dies gewünscht ist
                        subKey = regKey.CreateSubKey(pathToken[i]);
                    }
                    regKey = subKey;
                }
            }

            // Wert schreiben, wenn der Unterschlüssel gefunden wurde
            if (regKey != null)
            {
                regKey.SetValue(valueName, value);
            }
            else
            {
                // Ausnahme werfen
                throw new Exception("Schlüssel " + rootKey.ToString() + "\\" +
                                    keyPath + " nicht gefunden");
            }
        }
Example #6
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 #7
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 #8
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);
        }