/* Retrieves the type and data for the specified registry value. - Original documented types */
[DllImport("Advapi32.dll", EntryPoint = "RegGetValueW", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern LONG RegGetValue(
SafeRegistryHandle hkey,
string lpSubKey,
string lpValue,
EnumLib.RFlags dwFlags,
out EnumLib.RType pdwType,
IntPtr pvData,
ref DWORD pcbData);
/* Retrieves the type and data for the specified registry value. - C# Compliant types*/
[DllImport("Advapi32.dll", EntryPoint = "RegGetValueW", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern Int32 RegGetValue(
EnumLib.HKEY hkey,
string lpSubKey,
string lpValue,
RFlags dwFlags,
out RType pdwType,
IntPtr pvData,
ref UInt32 pcbData);
Declare Function RegGetValue Lib "advapi32.dll" (TODO) As TODO
/// <summary>
/// http://msdn.microsoft.com/en-us/library/windows/desktop/ms724884(v=vs.85).aspx
/// https://docs.microsoft.com/en-us/windows/desktop/api/Winreg/nf-winreg-reggetvaluea
/// </summary>
[Flags]
internal enum RFlags
{
/// <summary>
/// Any - No type restriction. (0x0000ffff)
/// </summary>
Any = 65535,
/// <summary>
/// Restrict type to REG_NONE. (0x00000001)
/// </summary>
RegNone = 1,
/// <summary>
/// Do not automatically expand environment strings if the value is of type REG_EXPAND_SZ. (0x10000000)
/// </summary>
Noexpand = 268435456,
/// <summary>
/// Bytes - Restrict type to REG_BINARY. (0x00000008)
/// </summary>
RegBinary = 8,
/// <summary>
/// Int32 - Restrict type to 32-bit RRF_RT_REG_BINARY | RRF_RT_REG_DWORD. (0x00000018)
/// </summary>
Dword = 24,
/// <summary>
/// Int32 - Restrict type to REG_DWORD. (0x00000010)
/// </summary>
RegDword = 16,
/// <summary>
/// Int64 - Restrict type to 64-bit RRF_RT_REG_BINARY | RRF_RT_REG_DWORD. (0x00000048)
/// </summary>
Qword = 72,
/// <summary>
/// Int64 - Restrict type to REG_QWORD. (0x00000040)
/// </summary>
RegQword = 64,
/// <summary>
/// A null-terminated string.
/// This will be either a Unicode or an ANSI string,
/// depending on whether you use the Unicode or ANSI functions.
/// Restrict type to REG_SZ. (0x00000002)
/// </summary>
RegSz = 2,
/// <summary>
/// A sequence of null-terminated strings, terminated by an empty string (\0).
/// The following is an example:
/// String1\0String2\0String3\0LastString\0\0
/// The first \0 terminates the first string, the second to the last \0 terminates the last string,
/// and the final \0 terminates the sequence. Note that the final terminator must be factored into the length of the string.
/// Restrict type to REG_MULTI_SZ. (0x00000020)
/// </summary>
RegMultiSz = 32,
/// <summary>
/// A null-terminated string that contains unexpanded references to environment variables (for example, "%PATH%").
/// It will be a Unicode or ANSI string depending on whether you use the Unicode or ANSI functions.
/// To expand the environment variable references, use the ExpandEnvironmentStrings function.
/// Restrict type to REG_EXPAND_SZ. (0x00000004)
/// </summary>
RegExpandSz = 4,
/// <summary>
/// If pvData is not NULL, set the contents of the buffer to zeroes on failure. (0x20000000)
/// </summary>
RrfZeroonfailure = 536870912
}
/// <summary>
/// http://msdn.microsoft.com/en-us/library/windows/desktop/ms724884(v=vs.85).aspx
/// </summary>
internal enum RType
{
RegNone= 0,
RegSz = 1,
RegExpandSz = 2,
RegMultiSz = 7,
RegBinary = 3,
RegDword = 4,
RegQword = 11,
RegQwordLittleEndian = 11,
RegDwordLittleEndian = 4,
RegDwordBigEndian = 5,
RegLink = 6,
RegResourceList = 8,
RegFullResourceDescriptor = 9,
RegResourceRequirementsList = 10,
}
Requires Windows Server 2003 SP1
Please add some!
uint pcbData = 0;
EnumLib.RType type;
var pvData = IntPtr.Zero;
Api.advapi32.RegGetValue(
EnumLib.HKEY.HKEY_CURRENT_USER,
@"Software\LG Electronics\LG PC Suite IV\1.0", @"DS_URL",
EnumLib.RFlags.Any,
out type, pvData, ref pcbData);
pvData = pvData.Reallocate(pcbData);
Api.advapi32.RegGetValue(
EnumLib.HKEY.HKEY_CURRENT_USER,
@"Software\LG Electronics\LG PC Suite IV\1.0", @"DS_URL",
type.ToFlag(),
out type, pvData, ref pcbData);
if (type == EnumLib.RType.RegSz)
Console.WriteLine(pvData.ToUnicodeStr());
Microsoft.Win32.Registry.GetValue()