Beispiel #1
0
        /// <summary>
        /// Writes a value in the registry. sample key format: "HKEY_LOCAL_MACHINE\Software\Microsoft\the folder".
        /// valueStr gets parsed depending on the kindName, which has to match with a member of the RegistryValueKind enum.
        /// </summary>
        internal static void Write(string key, string variable, string valueStr, string kindName)
        {
            // get the kind
            RegistryValueKind kind = (RegistryValueKind)Enum.Parse(typeof(RegistryValueKind), kindName);

            // convert the value to the appropriate kind
            object value = null;

            switch (kind)
            {
            case RegistryValueKind.DWord:
                value = Int32.Parse(valueStr);
                break;

            case RegistryValueKind.String:
                value = valueStr;
                break;

            default:
                throw (new NotSupportedException("not supported RegistryValueKind"));
            }

            Win32RegistryHelper.DisableRedirection(key);
            Microsoft.Win32.Registry.SetValue(key, variable, value);
            Win32RegistryHelper.EnableRedirection(key);
        }
Beispiel #2
0
 /// <summary>
 /// Writes a value in the registry. sample key format: "HKEY_LOCAL_MACHINE\Software\Microsoft\the folder"
 /// </summary>
 internal static void Write(string key, string variable, object value)
 {
     Win32RegistryHelper.DisableRedirection(key);
     Microsoft.Win32.Registry.SetValue(key, variable, value);
     Win32RegistryHelper.EnableRedirection(key);
 }