NanoByte.Common
Static Public Member Functions | List of all members
NanoByte.Common.RegistryUtils Class Reference

Provides utility and extension methods for Registry access. More...

Static Public Member Functions

static int GetDword ([NotNull, Localizable(false)] string keyName, [CanBeNull, Localizable(false)] string valueName, int defaultValue=0)
 Reads a DWORD value from the registry. More...
 
static void SetDword ([NotNull, Localizable(false)] string keyName, [CanBeNull, Localizable(false)] string valueName, int value)
 Sets a DWORD value in the registry. More...
 
static string GetString ([NotNull, Localizable(false)] string keyName, [CanBeNull, Localizable(false)] string valueName, [CanBeNull, Localizable(false)] string defaultValue=null)
 Reads a string value from the registry. More...
 
static void SetString ([NotNull, Localizable(false)] string keyName, [CanBeNull, Localizable(false)] string valueName, [NotNull, Localizable(false)] string value)
 Sets a string value in the registry. More...
 
static string GetSoftwareString ([NotNull, Localizable(false)] string subkeyName, [CanBeNull, Localizable(false)] string valueName, [CanBeNull, Localizable(false)] string defaultValue=null)
 Reads a string value from one of the SOFTWARE keys in the registry. More...
 
static string GetSoftwareString ([NotNull, Localizable(false)] string subkeyName, [CanBeNull, Localizable(false)] string valueName, bool machineWide)
 Reads a string value from one of the SOFTWARE keys in the registry. More...
 
static void SetSoftwareString ([NotNull, Localizable(false)] string subkeyName, [CanBeNull, Localizable(false)] string valueName, [NotNull, Localizable(false)] string value, bool machineWide=false)
 Sets a string value in one or more of the SOFTWARE keys in the registry. More...
 
static void DeleteSoftwareValue ([NotNull, Localizable(false)] string subkeyName, [NotNull, Localizable(false)] string valueName, bool machineWide)
 Deletes a value from one of the SOFTWARE keys in the registry. More...
 
static string [] GetValueNames ([NotNull, Localizable(false)] this RegistryKey key, [NotNull, Localizable(false)] string subkeyName)
 Retrieves the names of all values within a specific subkey of a registry root. More...
 
static string [] GetSubKeyNames ([NotNull, Localizable(false)] RegistryKey key, [NotNull, Localizable(false)] string subkeyName)
 Retrieves the names of all subkeys within a specific subkey of a registry root. More...
 
static RegistryKey OpenSubKeyChecked ([NotNull, Localizable(false)] this RegistryKey key, [NotNull, Localizable(false)] string subkeyName, bool writable=false)
 Like RegistryKey.OpenSubKey(string,bool) but with no null return values. More...
 
static RegistryKey CreateSubKeyChecked ([NotNull, Localizable(false)] this RegistryKey key, [NotNull, Localizable(false)] string subkeyName)
 Like RegistryKey.CreateSubKey(string) but with no null return values. More...
 
static RegistryKey OpenHklmKey ([NotNull, Localizable(false)] string subkeyName, out bool x64)
 Opens a HKEY_LOCAL_MACHINE key in the registry for reading, first trying to find the 64-bit version of it, then falling back to the 32-bit version. More...
 

Detailed Description

Provides utility and extension methods for Registry access.

Member Function Documentation

◆ CreateSubKeyChecked()

static RegistryKey NanoByte.Common.RegistryUtils.CreateSubKeyChecked ( [NotNull, Localizable(false)] this RegistryKey  key,
[NotNull, Localizable(false)] string  subkeyName 
)
inlinestatic

Like RegistryKey.CreateSubKey(string) but with no null return values.

Parameters
keyThe key to create a subkey in.
subkeyNameThe name of the subkey to create.
Returns
The newly created subkey.
Exceptions
IOExceptionFailed to create the key.
UnauthorizedAccessExceptionWrite access to the key is not permitted.

◆ DeleteSoftwareValue()

static void NanoByte.Common.RegistryUtils.DeleteSoftwareValue ( [NotNull, Localizable(false)] string  subkeyName,
[NotNull, Localizable(false)] string  valueName,
bool  machineWide 
)
inlinestatic

Deletes a value from one of the SOFTWARE keys in the registry.

Does not throw an exception for missing keys or values.

Parameters
subkeyNameThe path of the key relative to the SOFTWARE key.
valueNameThe name of the value to delete.
machineWidetrue to delete from HKLM/SOFTWARE (and HKLM/SOFTWARE/Wow6432Node if OSUtils.Is64BitProcess); false to delete from HCKU/SOFTWARE.
Exceptions
IOExceptionRegistry access failed.

◆ GetDword()

static int NanoByte.Common.RegistryUtils.GetDword ( [NotNull, Localizable(false)] string  keyName,
[CanBeNull, Localizable(false)] string  valueName,
int  defaultValue = 0 
)
inlinestatic

Reads a DWORD value from the registry.

Parameters
keyNameThe full path of the key to read from.
valueNameThe name of the value to read.
defaultValueThe default value to return if the key or value does not exist.
Exceptions
IOExceptionRegistry access failed.

◆ GetSoftwareString() [1/2]

static string NanoByte.Common.RegistryUtils.GetSoftwareString ( [NotNull, Localizable(false)] string  subkeyName,
[CanBeNull, Localizable(false)] string  valueName,
[CanBeNull, Localizable(false)] string  defaultValue = null 
)
inlinestatic

Reads a string value from one of the SOFTWARE keys in the registry.

Checks HKLM/SOFTWARE, HKLM/SOFTWARE/Wow6432Node and HKCU/SOFTWARE in that order.

Parameters
subkeyNameThe path of the key relative to the SOFTWARE key.
valueNameThe name of the value to read.
defaultValueThe default value to return if the key or value does not exist.
Exceptions
IOExceptionRegistry access failed.

◆ GetSoftwareString() [2/2]

static string NanoByte.Common.RegistryUtils.GetSoftwareString ( [NotNull, Localizable(false)] string  subkeyName,
[CanBeNull, Localizable(false)] string  valueName,
bool  machineWide 
)
inlinestatic

Reads a string value from one of the SOFTWARE keys in the registry.

Parameters
subkeyNameThe path of the key relative to the SOFTWARE key.
valueNameThe name of the value to read.
machineWidetrue to read from HKLM/SOFTWARE (and HKLM/SOFTWARE/Wow6432Node if OSUtils.Is64BitProcess); false to read from HCKU/SOFTWARE.
Exceptions
IOExceptionRegistry access failed.

◆ GetString()

static string NanoByte.Common.RegistryUtils.GetString ( [NotNull, Localizable(false)] string  keyName,
[CanBeNull, Localizable(false)] string  valueName,
[CanBeNull, Localizable(false)] string  defaultValue = null 
)
inlinestatic

Reads a string value from the registry.

Parameters
keyNameThe full path of the key to read from.
valueNameThe name of the value to read.
defaultValueThe default value to return if the key or value does not exist.
Exceptions
IOExceptionRegistry access failed.

◆ GetSubKeyNames()

static string [] NanoByte.Common.RegistryUtils.GetSubKeyNames ( [NotNull, Localizable(false)] RegistryKey  key,
[NotNull, Localizable(false)] string  subkeyName 
)
inlinestatic

Retrieves the names of all subkeys within a specific subkey of a registry root.

Parameters
keyThe root key to look within.
subkeyNameThe path of the subkey below key .
Returns
A list of key names; an empty array if the key does not exist.
Exceptions
IOExceptionRegistry access failed.

◆ GetValueNames()

static string [] NanoByte.Common.RegistryUtils.GetValueNames ( [NotNull, Localizable(false)] this RegistryKey  key,
[NotNull, Localizable(false)] string  subkeyName 
)
inlinestatic

Retrieves the names of all values within a specific subkey of a registry root.

Parameters
keyThe root key to look within.
subkeyNameThe path of the subkey below key .
Returns
A list of value names; an empty array if the key does not exist.
Exceptions
IOExceptionRegistry access failed.

◆ OpenHklmKey()

static RegistryKey NanoByte.Common.RegistryUtils.OpenHklmKey ( [NotNull, Localizable(false)] string  subkeyName,
out bool  x64 
)
inlinestatic

Opens a HKEY_LOCAL_MACHINE key in the registry for reading, first trying to find the 64-bit version of it, then falling back to the 32-bit version.

Parameters
subkeyNameThe path to the key below HKEY_LOCAL_MACHINE.
x64Indicates whether a 64-bit key was opened.
Returns
The opened registry key or null if it could not found.
Exceptions
IOExceptionFailed to open the key.
UnauthorizedAccessExceptionAccess to the key is not permitted.

◆ OpenSubKeyChecked()

static RegistryKey NanoByte.Common.RegistryUtils.OpenSubKeyChecked ( [NotNull, Localizable(false)] this RegistryKey  key,
[NotNull, Localizable(false)] string  subkeyName,
bool  writable = false 
)
inlinestatic

Like RegistryKey.OpenSubKey(string,bool) but with no null return values.

Parameters
keyThe key to open a subkey in.
subkeyNameThe name of the subkey to open.
writabletrue for write-access to the key.
Returns
The newly created subkey.
Exceptions
IOExceptionFailed to open the key.
UnauthorizedAccessExceptionAccess to the key is not permitted.

◆ SetDword()

static void NanoByte.Common.RegistryUtils.SetDword ( [NotNull, Localizable(false)] string  keyName,
[CanBeNull, Localizable(false)] string  valueName,
int  value 
)
inlinestatic

Sets a DWORD value in the registry.

Parameters
keyNameThe full path of the key to write to.
valueNameThe name of the value to write.
valueThe value to write.
Exceptions
IOExceptionRegistry access failed.
UnauthorizedAccessExceptionWrite access to the key is not permitted.

◆ SetSoftwareString()

static void NanoByte.Common.RegistryUtils.SetSoftwareString ( [NotNull, Localizable(false)] string  subkeyName,
[CanBeNull, Localizable(false)] string  valueName,
[NotNull, Localizable(false)] string  value,
bool  machineWide = false 
)
inlinestatic

Sets a string value in one or more of the SOFTWARE keys in the registry.

Parameters
subkeyNameThe path of the key relative to the SOFTWARE key.
valueNameThe name of the value to write.
valueThe value to write.
machineWidetrue to write to HKLM/SOFTWARE (and HKLM/SOFTWARE/Wow6432Node if OSUtils.Is64BitProcess); false to write to HCKU/SOFTWARE.
Exceptions
IOExceptionRegistry access failed.
UnauthorizedAccessExceptionWrite access to the key is not permitted.

◆ SetString()

static void NanoByte.Common.RegistryUtils.SetString ( [NotNull, Localizable(false)] string  keyName,
[CanBeNull, Localizable(false)] string  valueName,
[NotNull, Localizable(false)] string  value 
)
inlinestatic

Sets a string value in the registry.

Parameters
keyNameThe full path of the key to write to.
valueNameThe name of the value to write.
valueThe value to write.
Exceptions
IOExceptionRegistry access failed.
UnauthorizedAccessExceptionWrite access to the key is not permitted.

The documentation for this class was generated from the following file: