RegQueryValueEx (advapi32)
Last changed: philip.borchert@gmail.com-12.71.121.130

.
Summary
Retrieves the type and data for a specified value name associated with an open registry key.

C# Signature:

[DllImport("advapi32.dll", SetLastError=true)]
static extern int RegQueryValueEx(
    IntPtr hKey,
    string lpValueName,
    int lpReserved,
    out uint lpType,
    IntPtr lpData,
    out uint lpcbData);

VB Signature:

Declare Function RegQueryValueEx Lib "advapi32.dll" (ByRef hKey As Integer, _
    lpValueName As String, _
    lpReserved As Integer, _
    lpType As Integer, _
    ByRef lpData As Integer, _
    lpcbData As Integer) As Integer

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

[DllImport("advapi32.dll", EntryPoint="RegQueryValueEx", ExactSpelling=false, CharSet=CharSet.Unicode, SetLastError=true)]

private static extern int RegQueryValueEx_DllImport( IntPtr hKey, string lpValueName, int lpReserved, out uint lpType, StringBuilder lpData, ref uint lpcbData);

private void OpenRegKey()

{

   UIntPtr HkeyLocalMachine = (UIntPtr)0x80000002;
   const string lpSubKey = @"SYSTEM\CurrentControlSet\Control\Session Manager\Environment";
   const int KEY_QUERY_VALUE = 0x1;
   IntPtr hKeyVal;
   RegOpenKeyEx_DllImport(HkeyLocalMachine, lpSubKey, 0, KEY_QUERY_VALUE, out hKeyVal);

}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation