Ejemplo n.º 1
0
        // empty string in 'valueName' means "default" value stored in key
        public static StatusCode SetValue(string keyName, string valueName, object value, RegistryValueKind valueType = RegistryValueKind.Unknown)
        {
            Logger.CallStart(keyName, valueName, value, Enum.GetName(typeof(RegistryValueKind), valueType));

            keyName = keyName.Replace("HKCU", "HKEY_CURRENT_USER")
                      .Replace("HKLM", "HKEY_LOCAL_MACHINE")
                      .Replace("HKCR", "HKEY_CLASSES_ROOT")
                      .Replace("HKU", "HKEY_USERS")
                      .Replace("HKCC", "HKEY_CURRENT_CONFIG")
                      .Replace("HKPD", "HKEY_PERFORMANCE_DATA");


            try
            {
                W32Reg.SetValue(keyName, valueName, value, valueType);
                Logger.CallSucceeded();
                return(StatusCode.Success);
            }
            catch (Exception e)
            {
                Logger.LogException(e);
                return(StatusCode.Failure);
            }
        }