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

RegEnumKeyEx (advapi32)
 
.
Summary
Returns the list of sub key names from a given registry key. Analogous to getting a list of subdirectories

C# Signature:

        /// <summary> The RegEnumKeyEx function enumerates subkeys of the specified open registry key. </summary>
        /// <param name="hkey"> Handle to an open key. </param>
        /// <param name="index"> Index of the subkey to retrieve. </param>
        /// <param name="lpName"> Pointer to a buffer that receives the name of the subkey. </param>
        /// <param name="lpcbName"> Pointer to a variable that specifies the size of the buffer specified by the lpname parameter. </param>
        /// <param name="reserved"> Reserved; must be NULL. </param>
        /// <param name="lpClass"> Pointer to a buffer that receives the null-terminated class string of the enumerated subkey. </param>
        /// <param name="lpcbClass"> Pointer to a variable that specifies the size of the buffer specified by the lpClass parameter. </param>
        /// <param name="lpftLastWriteTime"> Pointer to a variable that receives the time at which the enumerated subkey was last written. </param>
        /// <returns> If the function succeeds, the return value is ERROR_SUCCESS (0). </returns>
        [DllImport("advapi32.dll", EntryPoint = "RegEnumKeyEx")]
        extern private static int RegEnumKeyEx(UIntPtr hkey, uint index, StringBuilder lpName, ref uint lpcbName,
            IntPtr reserved, IntPtr lpClass, IntPtr lpcbClass, out long lpftLastWriteTime);

VB Signature:

Declare Auto Function RegEnumKeyEx Lib "Advapi32" ( _
   ByVal hKey As IntPtr, _
   ByVal dwIndex As Integer, _
   ByVal lpName As StringBuilder, _
   ByRef lpcName As Integer, _
   ByVal lpReserved As IntPtr, _
   ByVal lpClass As IntPtr, _
   ByVal lpcClass As IntPtr, _
   ByVal lpftLastWriteTime As IntPtr _
) As Integer

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

LONG RegEnumKeyEx(
   HKEY hKey,
   DWORD dwIndex,
   LPTSTR lpName,
   LPDWORD lpcName,
   LPDWORD lpReserved,
   LPTSTR lpClass,
   LPDWORD lpcClass,
   PFILETIME lpftLastWriteTime
);

Tips & Tricks:

Please add some!

Sample Code:

Public Function GetSubKeyNames() As String()
   Dim i, ret, NameSize As Integer
   Dim sc As New StringCollection
   Dim sb As New StringBuilder(MAX_REG_KEYNAME_SIZE + 1)
   Dim ans(-1) As String

   ' quick sanity check
   If hKey.Equals(IntPtr.Zero) Then
     Throw New ApplicationException("Cannot access a closed registry key")
   End If

   Do
     NameSize = MAX_REG_KEYNAME_SIZE + 1
     ret = RegEnumKeyEx(hKey, i, sb, NameSize, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero)
     If ret <> 0 Then
       Exit Do
     End If
     sc.Add(sb.ToString)
     i += 1
   Loop

   If sc.Count > 0 Then
     ReDim ans(sc.Count - 1)
     sc.CopyTo(ans, 0)
   End If
   Return ans
End Function

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
Find References
Show Printable Version
Revisions