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
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
RegQueryInfoKey (advapi32)
 
.
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

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