Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than advapi32, prefix the name with the module name and a period.
RegGetValue (advapi32)
.
C# Signature:
/* 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);
[DllImport("advapi32.dll", SetLastError=true)]
static extern long RegGetValue(
IntPtr hkey,
string lpSubKey,
string lpValue,
uint dwFlags,
out IntPtr pdwType,
out IntPtr pvData,
ref IntPtr pcbData);
VB Signature:
Declare Function RegGetValue Lib "advapi32.dll" (TODO) As TODO
User-Defined Types:
/// <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,
None.
/// <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,
Tips & Tricks:
Please add some!
/// <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,
Sample Code:
Please add some!
/// <summary>
/// Int64 - Restrict type to REG_QWORD. (0x00000040)
/// </summary>
RegQword = 64,
Alternative Managed API:
/// <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,
Microsoft.Win32.Registry.GetValue()
/// <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
}
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());
Alternative Managed API:
Microsoft.Win32.Registry.GetValue()
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).