using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace Microsoft.Win32
{
/// Provides objects that represent the root keys in the Windows registry, and static methods to access key/value pairs.
// Token: 0x02000073 RID: 115
[ComVisible(true)]
public static class Registry
{
// Token: 0x06000701 RID: 1793 RVA: 0x000155C0 File Offset: 0x000137C0
private static RegistryKey ToKey(string keyName, bool setting)
{
if (keyName == null)
{
throw new ArgumentException("Not a valid registry key name", "keyName");
}
string[] array = keyName.Split(new char[] { '\\' });
string text = array[0];
if (text != null)
{
if (Registry.<>f__switch$map0 == null)
{
Registry.<>f__switch$map0 = new Dictionary(7)
{
{ "HKEY_CLASSES_ROOT", 0 },
{ "HKEY_CURRENT_CONFIG", 1 },
{ "HKEY_CURRENT_USER", 2 },
{ "HKEY_DYN_DATA", 3 },
{ "HKEY_LOCAL_MACHINE", 4 },
{ "HKEY_PERFORMANCE_DATA", 5 },
{ "HKEY_USERS", 6 }
};
}
int num;
if (Registry.<>f__switch$map0.TryGetValue(text, out num))
{
RegistryKey registryKey;
switch (num)
{
case 0:
registryKey = Registry.ClassesRoot;
break;
case 1:
registryKey = Registry.CurrentConfig;
break;
case 2:
registryKey = Registry.CurrentUser;
break;
case 3:
registryKey = Registry.DynData;
break;
case 4:
registryKey = Registry.LocalMachine;
break;
case 5:
registryKey = Registry.PerformanceData;
break;
case 6:
registryKey = Registry.Users;
break;
default:
goto IL_132;
}
for (int i = 1; i < array.Length; i++)
{
RegistryKey registryKey2 = registryKey.OpenSubKey(array[i], setting);
if (registryKey2 == null)
{
if (!setting)
{
return null;
}
registryKey2 = registryKey.CreateSubKey(array[i]);
}
registryKey = registryKey2;
}
return registryKey;
}
}
IL_132:
throw new ArgumentException("Keyname does not start with a valid registry root", "keyName");
}
/// Sets the specified name/value pair on the specified registry key. If the specified key does not exist, it is created.
/// The full registry path of the key, beginning with a valid registry root, such as "HKEY_CURRENT_USER".
/// The name of the name/value pair.
/// The value to be stored.
///
/// is null.
///
/// does not begin with a valid registry root.-or- is longer than the maximum length allowed (255 characters).
/// The is read-only, and thus cannot be written to; for example, it is a root-level node.
/// The user does not have the permissions required to create or modify registry keys.
///
///
///
///
// Token: 0x06000702 RID: 1794 RVA: 0x0001574C File Offset: 0x0001394C
public static void SetValue(string keyName, string valueName, object value)
{
RegistryKey registryKey = Registry.ToKey(keyName, true);
if (valueName.Length > 255)
{
throw new ArgumentException("valueName is larger than 255 characters", "valueName");
}
if (registryKey == null)
{
throw new ArgumentException("cant locate that keyName", "keyName");
}
registryKey.SetValue(valueName, value);
}
/// Sets the name/value pair on the specified registry key, using the specified registry data type. If the specified key does not exist, it is created.
/// The full registry path of the key, beginning with a valid registry root, such as "HKEY_CURRENT_USER".
/// The name of the name/value pair.
/// The value to be stored.
/// The registry data type to use when storing the data.
///
/// is null.
///
/// does not begin with a valid registry root.-or- is longer than the maximum length allowed (255 characters).-or- The type of did not match the registry data type specified by , therefore the data could not be converted properly.
/// The is read-only, and thus cannot be written to; for example, it is a root-level node, or the key has not been opened with write access.
/// The user does not have the permissions required to create or modify registry keys.
///
///
///
///
// Token: 0x06000703 RID: 1795 RVA: 0x000157A0 File Offset: 0x000139A0
public static void SetValue(string keyName, string valueName, object value, RegistryValueKind valueKind)
{
RegistryKey registryKey = Registry.ToKey(keyName, true);
if (valueName.Length > 255)
{
throw new ArgumentException("valueName is larger than 255 characters", "valueName");
}
if (registryKey == null)
{
throw new ArgumentException("cant locate that keyName", "keyName");
}
registryKey.SetValue(valueName, value, valueKind);
}
/// Retrieves the value associated with the specified name, in the specified registry key. If the name is not found in the specified key, returns a default value that you provide, or null if the specified key does not exist.
/// null if the subkey specified by does not exist; otherwise, the value associated with , or if is not found.
/// The full registry path of the key, beginning with a valid registry root, such as "HKEY_CURRENT_USER".
/// The name of the name/value pair.
/// The value to return if does not exist.
/// The user does not have the permissions required to read from the registry key.
/// The that contains the specified value has been marked for deletion.
///
/// does not begin with a valid registry root.
///
///
///
// Token: 0x06000704 RID: 1796 RVA: 0x000157F4 File Offset: 0x000139F4
public static object GetValue(string keyName, string valueName, object defaultValue)
{
RegistryKey registryKey = Registry.ToKey(keyName, false);
if (registryKey == null)
{
return defaultValue;
}
return registryKey.GetValue(valueName, defaultValue);
}
/// Defines the types (or classes) of documents and the properties associated with those types. This field reads the Windows registry base key HKEY_CLASSES_ROOT.
// Token: 0x040000DC RID: 220
public static readonly RegistryKey ClassesRoot = new RegistryKey(RegistryHive.ClassesRoot);
/// Contains configuration information pertaining to the hardware that is not specific to the user. This field reads the Windows registry base key HKEY_CURRENT_CONFIG.
// Token: 0x040000DD RID: 221
public static readonly RegistryKey CurrentConfig = new RegistryKey(RegistryHive.CurrentConfig);
/// Contains information about the current user preferences. This field reads the Windows registry base key HKEY_CURRENT_USER
// Token: 0x040000DE RID: 222
public static readonly RegistryKey CurrentUser = new RegistryKey(RegistryHive.CurrentUser);
/// Contains dynamic registry data. This field reads the Windows registry base key HKEY_DYN_DATA.
/// The operating system is not Windows 98, Windows 98 Second Edition, or Windows Millennium Edition.
// Token: 0x040000DF RID: 223
public static readonly RegistryKey DynData = new RegistryKey(RegistryHive.DynData);
/// Contains the configuration data for the local machine. This field reads the Windows registry base key HKEY_LOCAL_MACHINE.
// Token: 0x040000E0 RID: 224
public static readonly RegistryKey LocalMachine = new RegistryKey(RegistryHive.LocalMachine);
/// Contains performance information for software components. This field reads the Windows registry base key HKEY_PERFORMANCE_DATA.
// Token: 0x040000E1 RID: 225
public static readonly RegistryKey PerformanceData = new RegistryKey(RegistryHive.PerformanceData);
/// Contains information about the default user configuration. This field reads the Windows registry base key HKEY_USERS.
// Token: 0x040000E2 RID: 226
public static readonly RegistryKey Users = new RegistryKey(RegistryHive.Users);
}
}