Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. RegEnumKeyEx and WinXP

RegEnumKeyEx and WinXP

Scheduled Pinned Locked Moved Visual Basic
helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stefan b
    wrote on last edited by
    #1

    A VB code snippet that uses RegEnumKeyEx runs OK on Win'98 (the function returns ERROR_SUCCESS) but fails on WinXP! :mad: Any ideas? Thanks in advance, Stefan B.

    N 1 Reply Last reply
    0
    • S stefan b

      A VB code snippet that uses RegEnumKeyEx runs OK on Win'98 (the function returns ERROR_SUCCESS) but fails on WinXP! :mad: Any ideas? Thanks in advance, Stefan B.

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      Try this, it works on WinXP:

      Const ERROR_NO_MORE_ITEMS = 259&
      Const HKEY_CURRENT_CONFIG = &H80000005
      Const HKEY_LOCAL_MACHINE = &H80000002
      Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
      Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
      Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As Any) As Long
      Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
      Private Sub Form_Load()
      Dim hKey As Long, Cnt As Long, sName As String, sData As String, Ret As Long, RetData As Long
      Const BUFFER_SIZE As Long = 255
      'Set the forms graphics mode to persistent
      Me.AutoRedraw = True
      Me.Print "RegEnumKeyEx"
      Ret = BUFFER_SIZE
      'Open the registry key
      If RegOpenKey(HKEY_LOCAL_MACHINE, "Hardware", hKey) = 0 Then
      'Create a buffer
      sName = Space(BUFFER_SIZE)
      'Enumerate the keys
      While RegEnumKeyEx(hKey, Cnt, sName, Ret, ByVal 0&, vbNullString, ByVal 0&, ByVal 0&) <> ERROR_NO_MORE_ITEMS
      'Show the enumerated key
      Me.Print " " + Left$(sName, Ret)
      'prepare for the next key
      Cnt = Cnt + 1
      sName = Space(BUFFER_SIZE)
      Ret = BUFFER_SIZE
      Wend
      'close the registry key
      RegCloseKey hKey
      Else
      Me.Print " Error while calling RegOpenKey"
      End If
      Me.Print vbCrLf + "RegEnumValue"
      Cnt = 0
      'Open a registry key
      If RegOpenKey(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion", hKey) = 0 Then
      'initialize
      sName = Space(BUFFER_SIZE)
      sData = Space(BUFFER_SIZE)
      Ret = BUFFER_SIZE
      RetData = BUFFER_SIZE
      'enumerate the values
      While RegEnumValue(hKey, Cnt, sName, Ret, 0, ByVal 0&, ByVal sData, RetData) <> ERROR_NO_MORE_ITEMS
      'show data
      If RetData > 0 Then Me.Print " " + Left$(sName, Ret) + "=" + Left$(sData, RetData - 1)
      'prepare for next value
      Cnt = Cnt + 1

      S 1 Reply Last reply
      0
      • N Nick Parker

        Try this, it works on WinXP:

        Const ERROR_NO_MORE_ITEMS = 259&
        Const HKEY_CURRENT_CONFIG = &H80000005
        Const HKEY_LOCAL_MACHINE = &H80000002
        Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
        Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
        Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As Any) As Long
        Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
        Private Sub Form_Load()
        Dim hKey As Long, Cnt As Long, sName As String, sData As String, Ret As Long, RetData As Long
        Const BUFFER_SIZE As Long = 255
        'Set the forms graphics mode to persistent
        Me.AutoRedraw = True
        Me.Print "RegEnumKeyEx"
        Ret = BUFFER_SIZE
        'Open the registry key
        If RegOpenKey(HKEY_LOCAL_MACHINE, "Hardware", hKey) = 0 Then
        'Create a buffer
        sName = Space(BUFFER_SIZE)
        'Enumerate the keys
        While RegEnumKeyEx(hKey, Cnt, sName, Ret, ByVal 0&, vbNullString, ByVal 0&, ByVal 0&) <> ERROR_NO_MORE_ITEMS
        'Show the enumerated key
        Me.Print " " + Left$(sName, Ret)
        'prepare for the next key
        Cnt = Cnt + 1
        sName = Space(BUFFER_SIZE)
        Ret = BUFFER_SIZE
        Wend
        'close the registry key
        RegCloseKey hKey
        Else
        Me.Print " Error while calling RegOpenKey"
        End If
        Me.Print vbCrLf + "RegEnumValue"
        Cnt = 0
        'Open a registry key
        If RegOpenKey(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion", hKey) = 0 Then
        'initialize
        sName = Space(BUFFER_SIZE)
        sData = Space(BUFFER_SIZE)
        Ret = BUFFER_SIZE
        RetData = BUFFER_SIZE
        'enumerate the values
        While RegEnumValue(hKey, Cnt, sName, Ret, 0, ByVal 0&, ByVal sData, RetData) <> ERROR_NO_MORE_ITEMS
        'show data
        If RetData > 0 Then Me.Print " " + Left$(sName, Ret) + "=" + Left$(sData, RetData - 1)
        'prepare for next value
        Cnt = Cnt + 1

        S Offline
        S Offline
        stefan b
        wrote on last edited by
        #3

        Many, many thanks!!!!:rose: It's (almost) tha same code snippet I have played with, but I insisted to open HKEY_LOCAL_MACHINE\Enum (as in APIGuide's example), subkey that doesn't exist in WinXP, and when I noticed that, I forgot to restore some other unsuccesfull hacks:(. best regards, stefan b.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups