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

regenumvalue (advapi32)
 
.
Summary
The RegEnumValue function enumerates the values for the specified open registry key. The function copies one indexed value name and data block for the key each time it is called.

C# Signature:

[DllImport("advapi32.dll", SetLastError=true)]
static extern uint RegEnumValue(
      IntPtr hKey,
      uint dwIndex,
      StringBuilder lpValueName,
      ref uint lpcValueName,
      IntPtr lpReserved,
      IntPtr lpType,
      IntPtr lpData,
      IntPtr lpcbData);

VB Signature:

Declare Auto Function RegEnumValue Lib "Advapi32" ( _
   ByVal hKey As IntPtr, _
   ByVal dwIndex As Integer, _
   ByVal lpValueName As StringBuilder, _
   ByRef lpcValueName As Integer, _
   ByVal lpReserved As IntPtr, _
   ByVal lpType As IntPtr, _
   ByVal lpData As IntPtr, _
   ByVal lpcbData As IntPtr _
) As Integer

User-Defined Types:

None.

Alternative Managed API:

RegistryKey.GetValue

Notes:

LONG RegEnumValue(
   HKEY hKey,
   DWORD dwIndex,
   LPTSTR lpValueName,
   LPDWORD lpcValueName,
   LPDWORD lpReserved,
   LPDWORD lpType,
   LPBYTE lpData,
   LPDWORD lpcbData
);

Tips & Tricks:

Please add some!

Sample Code:

Public Function GetValueNames() 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 = RegEnumValue(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
Edit This Page
Find References
Show Printable Version
Revisions