RegQueryInfoKey (advapi32)
Last changed: -98.46.109.79

.
Summary
The RegQueryInfoKey function retrieves information about the specified registry key.

C# Signature:

[DllImport("advapi32.dll", EntryPoint="RegQueryInfoKey")]
extern private static int RegQueryInfoKey(
    UIntPtr hkey,
    out StringBuilder lpClass,
    ref uint lpcbClass,
    IntPtr lpReserved,
    out uint lpcSubKeys,
    out uint lpcbMaxSubKeyLen,
    out uint lpcbMaxClassLen,
    out uint lpcValues,
    out uint lpcbMaxValueNameLen,
    out uint lpcbMaxValueLen,
    out uint lpcbSecurityDescriptor,
    IntPtr lpftLastWriteTime);

VB Signature:

Public Declare Auto Function RegQueryInfoKey Lib "advapi32.dll" (
    ByVal hKey As UIntPtr,
    ByVal lpClass As System.Text.StringBuilder,
    ByRef lpcbClass As Integer,
    ByVal lpReserved As IntPtr,
    ByRef lpcSubKeys As Integer,
    ByRef lpcbMaxSubKeyLen As Integer,
    ByRef lpcbMaxClassLen As Integer,
    ByRef lpcValues As Integer,
    ByRef lpcbMaxValueNameLen As Integer,
    ByRef lpcMaxValueLen As Integer,
    ByRef lpcbSecurityDescriptor As Integer,
    ByVal lpftLastWriteTime As IntPtr
) As Integer

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

Beware both lpcbMaxSubKeyLen and lpcbMaxValueNameLen return the length of the longest SubKey/Value Name, in Unicode characters. However, the size does not include the terminating null character!

Tips & Tricks:

Please add some!

Sample Code:

    Dim hk As UIntPtr : hk = RegOpenKeyEx ...
    Dim lpcSubKeys As Integer
    Dim lpcbMaxSubKeyLen As Integer
    Dim lpcbMaxClassLen As Integer
    Dim lpcValues As Integer
    Dim lpcbMaxValueNameLen As Integer
    Dim lpcMaxValueLen As Integer
    Dim lpcbSecurityDescriptor As Integer
    Dim sbClass = New Text.StringBuilder(1024)
    Dim sbClassLen = sbClass.Capacity
    r = PInvoke.RegQueryInfoKey(hk, sbClass, sbClassLen, IntPtr.Zero, lpcSubKeys, lpcbMaxSubKeyLen, lpcbMaxClassLen, lpcValues, lpcbMaxValueNameLen, lpcMaxValueLen, lpcbSecurityDescriptor, IntPtr.Zero)
    Console.WriteLine("Return={0}, hkey={1}, lpcSubKeys={2}, lpcbMaxSubKeyLen={3}, lpcbMaxClassLen={4}, lpcValues={5}, lpcbMaxValueNameLen={6}, lpcMaxValueLen={7}, lpcbSecurityDescriptor={8}",
        r,
        hk,
        lpcSubKeys,
        lpcbMaxSubKeyLen,
        lpcbMaxClassLen,
        lpcValues,
        lpcbMaxValueNameLen,
        lpcMaxValueLen,
        lpcbSecurityDescriptor)
    Console.WriteLine("Class={0}", sbClass.ToString) 'usually empty

Documentation