Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

RegGetValue (advapi32)
 
.
Summary
Retrieves the type and data for the specified registry value

C# Signature:

        /* Retrieves the type and data for the specified registry value. */
        [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. */
        [DllImport("Advapi32.dll", EntryPoint = "RegGetValueW", CharSet = CharSet.Unicode, SetLastError = true)]
        internal static extern LONG RegGetValue(
        EnumLib.HKEY hkey,
        string lpSubKey,
        string lpValue,
        EnumLib.RFlags dwFlags,
        out EnumLib.RType pdwType,
        IntPtr pvData,
        ref DWORD pcbData);
[DllImport("advapi32.dll", SetLastError=true)]
static extern long RegGetValue(
    IntPtr hkey,
    string lpSubKey,
    string lpValue,
    uint dwFlags,
    out IntPtr pdwType,
    out IntPtr pvData,
    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
    /// </summary>
    internal enum RFlags
    {
        /// <summary>
        /// Any
        /// </summary>
        Any = 65535,

None.

        /// <summary>
        /// No defined value type.
        /// </summary>
        RegNone = 1,

Notes:

Requires Windows Server 2003 SP1

        /// <summary>
        /// ???
        /// </summary>
        Noexpand = 268435456,

        /// <summary>
        /// Bytes
        /// </summary>
        RegBinary = 8,

        /// <summary>
        /// Int32
        /// </summary>
        Dword = 24,

Tips & Tricks:

Please add some!

        /// <summary>
        /// Int32
        /// </summary>
        RegDword = 16,

        /// <summary>
        /// Int64
        /// </summary>
        Qword = 72,

Sample Code:

Please add some!

        /// <summary>
        /// Int64
        /// </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.
        /// </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.
        /// </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.
        /// </summary>
        RegExpandSz = 4,

        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,
    }

Notes:

Requires Windows Server 2003 SP1

Tips & Tricks:

Please add some!

Sample Code:

        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()

Documentation
RegGetValue on MSDN

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).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions