public bool Write(RegistryDataTypes registryDataEntry)
        {
            if (registryDataEntry.Data == null)
            {
                return(false);
            }

            try
            {
                RegistryKey rk  = this._baseRegistryKey;
                RegistryKey sk1 = rk.CreateSubKey(this._subKey);

                if (sk1 != null)
                {
                    sk1.SetValue(registryDataEntry.KeyName, registryDataEntry.Data, registryDataEntry.DataType);
                }

                return(true);
            }
            catch (Exception e)
            {
                this.ShowErrorMessage(e, "Writing registry " + registryDataEntry.KeyName);
                return(false);
            }
        }
 public void SaveObjectToRegistry(object objToSave)
 {
     try
     {
         Type           objType    = objToSave.GetType();
         PropertyInfo[] properties = objType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
         foreach (PropertyInfo propertyInfo in properties)
         {
             string            propertyName = propertyInfo.Name;
             RegistryDataTypes registryData = null;
             if (propertyInfo.PropertyType == typeof(string))
             {
                 registryData = new RegistryDataTypeString {
                     KeyName = propertyName, Data = propertyInfo.GetValue(objToSave)
                 };
             }
             else if (propertyInfo.PropertyType == typeof(int))
             {
                 registryData = new RegistryDataTypeDWORD {
                     KeyName = propertyName, Data = propertyInfo.GetValue(objToSave)
                 };
             }
             else if (propertyInfo.PropertyType == typeof(bool))
             {
                 registryData = new RegistryDataTypeString {
                     KeyName = propertyName, Data = ((bool)propertyInfo.GetValue(objToSave)) ? "true" : "false"
                 };
             }
             else if (propertyInfo.PropertyType.BaseType == typeof(Enum))
             {
                 registryData = new RegistryDataTypeDWORD {
                     KeyName = propertyName, Data = (int)propertyInfo.GetValue(objToSave)
                 };
             }
             if (registryData != null)
             {
                 Write(registryData);
             }
         }
     }
     catch (Exception e)
     {
         this.ShowErrorMessage(e, "SaveObjectToRegistry");
     }
 }