Solved

MaxMTU Registry Question

Posted on 1998-11-22
13
132 Views
Last Modified: 2010-05-03
I'm trying to figure out how to query for the MaxMTU in the Registry under HKEY_LOCAL_MACHINE System\CurrentControlSet\Services\Class\NetTrans\

Now the problem is when you install another network driver other then TCP/IP like IPX/SPX it adds more subkeys like \0002 \0003 One of those subkeys contains 0.0.0.0 for the DUN IP address and the MaxMTU is in that same subkey area, how do i query the MaxMTU value in that same area?? Each computer seems to have the MaxMTU located in a seperate Subkey under NetTrans\, sometimes its in NetTrans\0000 and sometimes its in NetTrans\0002 depending on how many network drivers they have loaded. One of my systems has clear up to \0008 and the MaxMTU is located in like \0005.

 I will add more points for a thorough answer! Thanks in advance!
0
Comment
Question by:wookie7
  • 7
  • 4
  • 2
13 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1446148
You must be using win95!
Did you also ask the question to retrieve this registry entry for 750?
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1446149
Enumerate all subkeys of Nettrans until you find the right one. There is no way of telling in front which one is the right one.
0
 

Author Comment

by:wookie7
ID: 1446150
I agree with the enumeration but how would i go about that, oh and i should add that you can have more then one TCP/IP driver installed, like having a network card along side of Dialup Network Adapter, which means there could be more then one MaxMTU, gotta find the one specifically for DUN.
0
 

Author Comment

by:wookie7
ID: 1446151
Adjusted points to 105
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1446152
HMM, 5 additional points.
Bindings can be found in HKEY_LOCAL_MACHINE\Enum\Network
Here you will find all the Network clients/protocols/services. The subkey Bindings connects the child to its parents.
So open MSTCP. In your example there could be two entries there 0000 and 0001. The first one can point to NETTRANS\0000 and the second one to NETTRANS\0003 for example (here you can bind the DHCP settings)
Now look in the subkey Bindings and find out to which services it is bound. Check in DUN is one of them.
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1446153
HMM, 5 additional points.
Bindings can be found in HKEY_LOCAL_MACHINE\Enum\Network
Here you will find all the Network clients/protocols/services. The subkey Bindings connects the child to its parents.
So open MSTCP. In your example there could be two entries there 0000 and 0001. The first one can point to NETTRANS\0000 and the second one to NETTRANS\0003 for example (here you can bind the DHCP settings)
Now look in the subkey Bindings and find out to which services it is bound. Check in DUN is one of them.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:wookie7
ID: 1446154
Hehe ok you have any idea of how im gonna do that?
0
 

Author Comment

by:wookie7
ID: 1446155
Hehe ok you have any idea of how im gonna do that?
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1446156
How do you mean? Do you want me to write it for you or do you need functions to access the registry?
0
 
LVL 2

Expert Comment

by:spenner
ID: 1446157
This is the code I use to manipulate the registry - it includes create/edit/query registry

'@@@@@@@@ Insert this Code into a Module @@@@@@@@

   Public Const REG_SZ As Long = 1
   Public Const REG_DWORD As Long = 4

   Public Const HKEY_CLASSES_ROOT = &H80000000
   Public Const HKEY_CURRENT_USER = &H80000001
   Public Const HKEY_LOCAL_MACHINE = &H80000002
   Public Const HKEY_USERS = &H80000003

   Public Const ERROR_NONE = 0
   Public Const ERROR_BADDB = 1
   Public Const ERROR_BADKEY = 2
   Public Const ERROR_CANTOPEN = 3
   Public Const ERROR_CANTREAD = 4
   Public Const ERROR_CANTWRITE = 5
   Public Const ERROR_OUTOFMEMORY = 6
   Public Const ERROR_ARENA_TRASHED = 7
   Public Const ERROR_ACCESS_DENIED = 8
   Public Const ERROR_INVALID_PARAMETERS = 87
   Public Const ERROR_NO_MORE_ITEMS = 259

   Public Const KEY_ALL_ACCESS = &H3F

   Public Const REG_OPTION_NON_VOLATILE = 0

   Declare Function RegCloseKey Lib "advapi32.dll" _
   (ByVal hKey As Long) As Long
   Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias _
   "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
   ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions _
   As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes _
   As Long, phkResult As Long, lpdwDisposition As Long) As Long
   Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
   "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
   ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As _
   Long) As Long
   Declare Function RegQueryValueExString Lib "advapi32.dll" Alias _
   "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
   String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
   As String, lpcbData As Long) As Long
   Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias _
   "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
   String, ByVal lpReserved As Long, lpType As Long, lpData As _
   Long, lpcbData As Long) As Long
   Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias _
   "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
   String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
   As Long, lpcbData As Long) As Long
   Declare Function RegSetValueExString Lib "advapi32.dll" Alias _
   "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
   ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As _
   String, ByVal cbData As Long) As Long
   Declare Function RegSetValueExLong Lib "advapi32.dll" Alias _
   "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
   ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, _
   ByVal cbData As Long) As Long

   ' SetValueEx and QueryValueEx Wrapper Functions:

   Public Function SetValueEx(ByVal hKey As Long, sValueName As String, _
   lType As Long, vValue As Variant) As Long
       Dim lValue As Long
       Dim sValue As String
       Select Case lType
           Case REG_SZ
               sValue = vValue & Chr$(0)
               SetValueEx = RegSetValueExString(hKey, sValueName, 0&, _
                                              lType, sValue, Len(sValue))
           Case REG_DWORD
               lValue = vValue
               SetValueEx = RegSetValueExLong(hKey, sValueName, 0&, _
   lType, lValue, 4)
           End Select
   End Function

   Function QueryValueEx(ByVal lhKey As Long, ByVal szValueName As _
   String, vValue As Variant) As Long
       Dim cch As Long
       Dim lrc As Long
       Dim lType As Long
       Dim lValue As Long
       Dim sValue As String

       On Error GoTo QueryValueExError

       ' Determine the size and type of data to be read
       lrc = RegQueryValueExNULL(lhKey, szValueName, 0&, lType, 0&, cch)
       If lrc <> ERROR_NONE Then Error 5

       Select Case lType
           ' For strings
           Case REG_SZ:
               sValue = String(cch, 0)
   lrc = RegQueryValueExString(lhKey, szValueName, 0&, lType, _
   sValue, cch)
               If lrc = ERROR_NONE Then
                   vValue = Left$(sValue, cch - 1)
               Else
                   vValue = Empty
               End If
           ' For DWORDS
           Case REG_DWORD:
   lrc = RegQueryValueExLong(lhKey, szValueName, 0&, lType, _
   lValue, cch)
               If lrc = ERROR_NONE Then vValue = lValue
           Case Else
               'all other data types not supported
               lrc = -1
       End Select

QueryValueExExit:
       QueryValueEx = lrc
       Exit Function

QueryValueExError:
       Resume QueryValueExExit

End Function



'@@@@@@@@ Insert this Code into a Form @@@@@@@@

'*********************************************************************
' Create a new Registry Key
' - Call it like this
'   CreateNewKey "TestKey\SubKey1\SubKey2", HKEY_LOCAL_MACHINE
'
' This will create three-nested keys beginning with TestKey
' immediately under HKEY_LOCAL_MACHINE, SubKey1 subordinate
' to TestKey, and SubKey3 under SubKey2.
'

Private Sub CreateNewKey(sNewKeyName As String, lPredefinedKey As Long)
    Dim hNewKey As Long         'handle to the new key
    Dim lRetVal As Long         'result of the RegCreateKeyEx function
   
    lRetVal = RegCreateKeyEx(lPredefinedKey, sNewKeyName, 0&, _
                 vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, _
                 0&, hNewKey, lRetVal)
    RegCloseKey (hNewKey)
End Sub

'*********************************************************************
' Set a Registry Key Value
' - Call it like this
'   SetKeyValue "TestKey\SubKey1", "StringValue", "Hello", REG_SZ
'
'  This will create a value of type REG_SZ called "SubKey1" with
'  the setting of "Hello." This value will be associated with the
'  key SubKey1 of "TestKey."
'

Private Sub SetKeyValue(sKeyName As String, sValueName As String, _
    vValueSetting As Variant, lValueType As Long)
   
    Dim lRetVal As Long         'result of the SetValueEx function
    Dim hKey As Long         'handle of open key

    'open the specified key
    lRetVal = RegOpenKeyEx(HKEY_CURRENT_USER, sKeyName, 0, _
                            KEY_ALL_ACCESS, hKey)
    lRetVal = SetValueEx(hKey, sValueName, lValueType, vValueSetting)
    RegCloseKey (hKey)
End Sub

'*********************************************************************
' Query the value of a key
' - Call it like this
'   QueryValue "TestKey\SubKey1", "StringValue"
'
'  This will display a message box with the current setting of
'  the "StringValue" value, and assumes that "StringValue" exists
'  in the "TestKey\SubKey1" key.  If the Value that you query
'  does not exist then QueryValue will return an error code of
'  2 - 'ERROR_BADKEY'.
'

Private Sub QueryValue(sKeyName As String, sValueName As String)
    Dim lRetVal As Long         'result of the API functions
    Dim hKey As Long         'handle of opened key
    Dim vValue As Variant      'setting of queried value

    lRetVal = RegOpenKeyEx(HKEY_CURRENT_USER, sKeyName, 0, _
        KEY_ALL_ACCESS, hKey)
    lRetVal = QueryValueEx(hKey, sValueName, vValue)
    MsgBox vValue             ' vValue stores the returned value
    RegCloseKey (hKey)
End Sub
0
 
LVL 2

Expert Comment

by:spenner
ID: 1446158
I should note that the above code is taken straight from the knowledge base
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1446159
Yeh, and also note that the above code does not do enumeration.
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 150 total points
ID: 1446160
Attribute VB_Name = "ModReg"
Option Explicit

   Public Const REG_SZ As Long = 1
   Public Const REG_DWORD As Long = 4
   Public Const REG_EXPAND_SZ = 2
   Declare Function ExpandEnvironmentStrings Lib "kernel32" Alias "ExpandEnvironmentStringsA" (ByVal lpSrc As String, ByVal lpDst As String, ByVal nSize As Long) As Long
   Type FILETIME
           dwLowDateTime As Long
           dwHighDateTime As Long
   End Type

   Public Const HKEY_CLASSES_ROOT = &H80000000
   Public Const HKEY_CURRENT_USER = &H80000001
   Public Const HKEY_LOCAL_MACHINE = &H80000002
   Public Const HKEY_USERS = &H80000003

   Public Const ERROR_NONE = 0
   Public Const ERROR_BADDB = 1
   Public Const ERROR_BADKEY = 2
   Public Const ERROR_CANTOPEN = 3
   Public Const ERROR_CANTREAD = 4
   Public Const ERROR_CANTWRITE = 5
   Public Const ERROR_OUTOFMEMORY = 6
   Public Const ERROR_INVALID_PARAMETER = 7
   Public Const ERROR_ACCESS_DENIED = 8
   Public Const ERROR_INVALID_PARAMETERS = 87
   Public Const ERROR_NO_MORE_ITEMS = 259

   Public Const KEY_ALL_ACCESS = &H3F

   Public Const REG_OPTION_NON_VOLATILE = 0

   Declare Function RegCloseKey Lib "advapi32.dll" _
   (ByVal hKey As Long) As Long
   Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias _
   "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
   ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions _
   As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes _
   As Long, phkResult As Long, lpdwDisposition As Long) As Long
   Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
   "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
   ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As _
   Long) As Long
   Declare Function RegQueryValueExString Lib "advapi32.dll" Alias _
   "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
   String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
   As String, lpcbData As Long) As Long
   Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias _
   "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
   String, ByVal lpReserved As Long, lpType As Long, lpData As _
   Long, lpcbData As Long) As Long
   Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias _
   "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
   String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
   As Long, lpcbData As Long) As Long
   Declare Function RegSetValueExString Lib "advapi32.dll" Alias _
   "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
   ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As _
   String, ByVal cbData As Long) As Long
   Declare Function RegSetValueExLong Lib "advapi32.dll" Alias _
   "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
   ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, _
   ByVal cbData As Long) As Long
   Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" ( _
      ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, _
      ByVal cbName As Long) As Long
   Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" ( _
      ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, _
      lpcbName As Long, lpReserved As Long, ByVal lpClass As String, _
      lpcbClass As Long, lpftLastWriteTime As FILETIME) As Long
   Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" ( _
      ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, _
      lpcbValueName As Long, lpReserved As Long, lpType As Long, _
      lpData As Byte, lpcbData As Long) As Long
   Declare Function RegQueryInfoKey Lib "advapi32.dll" Alias "RegQueryInfoKeyA" ( _
      ByVal hKey As Long, ByVal lpClass As String, lpcbClass As Long, lpReserved As Long, _
      lpcSubKeys As Long, lpcbMaxSubKeyLen As Long, lpcbMaxClassLen As Long, lpcValues As Long, _
      lpcbMaxValueNameLen As Long, lpcbMaxValueLen As Long, _
      lpcbSecurityDescriptor As Long, lpftLastWriteTime As FILETIME) As Long
     


'***********************************
'********* SetValueEx
'***********************************
Public Function SetValueEx(ByVal hKey As Long, sValueName As String, _
   ltype As Long, vValue As Variant) As Long
       Dim lValue As Long
       Dim sValue As String
       Select Case ltype
           Case REG_SZ
               sValue = vValue + Chr$(0)
               SetValueEx = RegSetValueExString(hKey, sValueName, 0&, _
                                              ltype, sValue, Len(sValue))
           Case REG_DWORD
               lValue = vValue
               Debug.Assert Len(sValueName) > 0 ' That does not work on windows 95
               SetValueEx = RegSetValueExLong(hKey, sValueName, 0&, ltype, lValue, 4)
            Case Else
               Debug.Assert 0
           End Select
   End Function

'***********************************
'********* QueryValueEx
'***********************************
Function QueryValueEx(ByVal lhKey As Long, ByVal szValueName As _
   String, vValue As Variant) As Long
       Dim cch As Long
       Dim lrc As Long
       Dim ltype As Long
       Dim lValue As Long
       Dim sValue As String

       On Error GoTo QueryValueExError

       ' Determine the size and type of data to be read
       lrc = RegQueryValueExNULL(lhKey, szValueName, 0&, ltype, 0&, cch)
       If lrc <> ERROR_NONE Then Error 5

       Select Case ltype
           ' For strings
           Case REG_SZ:
               sValue = String$(cch, 0)
               lrc = RegQueryValueExString(lhKey, szValueName, 0&, ltype, _
                                             sValue, cch)
               If lrc = ERROR_NONE Then
                    If (cch > 1) Then
                        vValue = Left$(sValue, cch - 1)
                    Else
                        vValue = ""
                    End If
               Else
                   vValue = Empty
               End If
           ' For DWORDS
           Case REG_DWORD:
               lrc = RegQueryValueExLong(lhKey, szValueName, 0&, ltype, _
                                          lValue, cch)
               If lrc = ERROR_NONE Then vValue = lValue
           Case REG_EXPAND_SZ:
               sValue = String$(cch, 0)
               lrc = RegQueryValueExString(lhKey, szValueName, 0&, ltype, _
                                             sValue, cch)
               If lrc = ERROR_NONE Then
                   Dim result As String
                   result = String$(2048, 0)
                   Dim size As Integer
                   size = ExpandEnvironmentStrings(Left$(sValue, cch - 1), result, 2048)
                   sValue = Left(result, size)
                   vValue = sValue
               Else
                   vValue = Empty
               End If
           Case Else
               'all other data types not supported
               lrc = -1
       End Select

QueryValueExExit:
       QueryValueEx = lrc
       Exit Function
QueryValueExError:
       Resume QueryValueExExit
   End Function

'***********************************
'********* EnumKey
'***********************************
Public Function EnumKey(ByVal hKey As Long, ByVal index As Long, ByRef key As String) As Long
   Dim cch As Long
   Dim lrc As Long
   Dim ltype As Long
   Dim lValue As Long
   Dim szKeyName As String
   
   cch = 260
   szKeyName = String$(cch, 0)
   lrc = RegEnumKey(hKey, index, szKeyName, cch)
   
   If (lrc = 0) Then
      key = Left$(szKeyName, InStr(szKeyName, Chr$(0)) - 1)
   End If
   
   EnumKey = lrc
End Function


'***********************************
'********* EnumValue
'***********************************
Public Function EnumValue(ByVal hKey As Long, ByVal index As Long, ByRef valueName As String) As Long
   Dim cch As Long
   Dim lrc As Long
   Dim ltype As Long
   Dim lValue As Long
   Dim szValueName As String
   
   'Not tested yet
   Debug.Assert 0
   
   cch = 260
   szValueName = String$(cch, 0)
   lrc = RegEnumValue(hKey, index, szValueName, cch, 0, 0, 0, 0)
   
   If (lrc = 0) Then
      valueName = Left$(szValueName, InStr(szValueName, Chr$(0)) - 1)
   End If
   
   EnumValue = lrc
End Function


'***********************************
'********* SetXXXValue
'***********************************
Public Sub SetXXXValue(ByVal RootKey As Long, ByVal sKeyName As String, ByVal sValueName As String, ByVal ltype As Long, ByVal value As Variant)
    Dim lRetval As Long         'result of the API functions
    Dim hKey As Long         'handle of opened key
    Dim lDispo As Long

    lRetval = RegOpenKeyEx(RootKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
    If (lRetval <> 0) Then
       lRetval = RegCreateKeyEx(RootKey, sKeyName, 0, "", 0, KEY_ALL_ACCESS, 0, hKey, lDispo)
    End If
    If (lRetval = 0) Then
        lRetval = SetValueEx(hKey, sValueName, ltype, value)
        RegCloseKey (hKey)
    End If
End Sub

Public Sub SetUserValue(ByVal sKeyName As String, ByVal sValueName As String, ByVal ltype As Long, ByVal value As Variant)
   SetXXXValue HKEY_CURRENT_USER, sKeyName, sValueName, ltype, value
End Sub

Public Sub SetMachineValue(ByVal sKeyName As String, ByVal sValueName As String, ByVal ltype As Long, ByVal value As Variant)
   SetXXXValue HKEY_LOCAL_MACHINE, sKeyName, sValueName, ltype, value
End Sub

Public Sub SetClassesValue(ByVal sKeyName As String, ByVal sValueName As String, ByVal ltype As Long, ByVal value As Variant)
   SetXXXValue HKEY_CLASSES_ROOT, sKeyName, sValueName, ltype, value
End Sub

'***********************************
'********* QueryXXXValue
'***********************************

Public Function QueryXXXValue(ByVal RootKey As Long, ByVal sKeyName As String, ByVal sValueName As String) As Variant
    Dim lRetval As Long         'result of the API functions
    Dim hKey As Long         'handle of opened key
    Dim vValue As Variant      'setting of queried value

    lRetval = RegOpenKeyEx(RootKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
    If (lRetval = 0) Then
      lRetval = QueryValueEx(hKey, sValueName, vValue)
       If Not (lRetval = 0) Then
         vValue = Empty
       End If
        RegCloseKey (hKey)
    End If
   
    QueryXXXValue = vValue
End Function

Public Function QueryUserValue(ByVal sKeyName As String, ByVal sValueName As String) As Variant
   QueryUserValue = QueryXXXValue(HKEY_CURRENT_USER, sKeyName, sValueName)
End Function

Public Function QueryMachineValue(ByVal sKeyName As String, ByVal sValueName As String) As Variant
   QueryMachineValue = QueryXXXValue(HKEY_LOCAL_MACHINE, sKeyName, sValueName)
End Function

Public Function QueryClassesValue(ByVal sKeyName As String, ByVal sValueName As String) As Variant
   QueryClassesValue = QueryXXXValue(HKEY_CLASSES_ROOT, sKeyName, sValueName)
End Function

'***********************************
'********* EnumXXXValues
'***********************************
Public Function EnumXXXValues(ByVal RootKey As Long, ByVal sKeyName As String) As Variant
   Dim i As Long
   Dim nrValues As Long
   Dim lrc As Long
   Dim value As String
   Dim hKey As Long
   Dim AllValuesCollection As New Collection
   Dim lRetval As Long
   Dim vValues() As String
   
   
   On Error GoTo leave
   hKey = 0
   lRetval = RegOpenKeyEx(RootKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
   If (lRetval = 0) Then
      lrc = 0
      i = 0
      'Request all Values
      While lrc = 0
         lrc = EnumValue(hKey, i, value)
         If (lrc = 0) Then
            i = i + 1
            AllValuesCollection.Add value, "Value" & i
         End If
      Wend
     
      'Copy all Values in a variant array
      If (i > 0) Then
         nrValues = i
         ReDim vValues(nrValues - 1) As String
         For i = 1 To nrValues
            vValues(i - 1) = AllValuesCollection("Value" & i)
         Next
      End If
   End If
   
   'Set return value
   EnumXXXValues = vValues
leave:
    If (hKey <> 0) Then
        RegCloseKey hKey
    End If
End Function

Public Function EnumUserValues(ByVal sKeyName As String) As Variant
   EnumUserValues = EnumXXXValues(HKEY_CURRENT_USER, sKeyName)
End Function

Public Function EnumMachineValues(ByVal sKeyName As String) As Variant
   EnumMachineValues = EnumXXXValues(HKEY_LOCAL_MACHINE, sKeyName)
End Function

Public Function EnumClassesValues(ByVal sKeyName As String) As Variant
   EnumClassesValues = EnumXXXValues(HKEY_CLASSES_ROOT, sKeyName)
End Function

'***********************************
'********* EnumXXXKeys
'***********************************
Public Function EnumXXXKeys(ByVal RootKey As Long, ByVal sKeyName As String) As Variant
   Dim i As Long
   Dim nrKeys As Long
   Dim lrc As Long
   Dim key As String
   Dim hKey As Long
   Dim AllKeysCollection As New Collection
   Dim vKeys() As String
   Dim lRetval As Long
   
   
   
   On Error GoTo leave
   hKey = 0
   lRetval = RegOpenKeyEx(RootKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
   If (lRetval = 0) Then
      lrc = 0
      i = 0
      'Request all keys
      While lrc = 0
         lrc = EnumKey(hKey, i, key)
         If (lrc = 0) Then
            i = i + 1
            AllKeysCollection.Add key, "Key" & i
         End If
      Wend
     
      'Copy all keys in a variant array
      If (i > 0) Then
         nrKeys = i
         ReDim vKeys(nrKeys - 1) As String
         For i = 1 To nrKeys
            vKeys(i - 1) = AllKeysCollection("Key" & i)
         Next
      End If
   End If
   
   'Set return value
   EnumXXXKeys = vKeys
leave:
    If (hKey <> 0) Then
        RegCloseKey hKey
    End If
End Function

Public Function EnumUserKeys(ByVal sKeyName As String) As Variant
   EnumUserKeys = EnumXXXKeys(HKEY_CURRENT_USER, sKeyName)
End Function

Public Function EnumMachineKeys(ByVal sKeyName As String) As Variant
   EnumMachineKeys = EnumXXXKeys(HKEY_LOCAL_MACHINE, sKeyName)
End Function

Public Function EnumClassesKeys(ByVal sKeyName As String) As Variant
   EnumClassesKeys = EnumXXXKeys(HKEY_CLASSES_ROOT, sKeyName)
End Function

Public Function RegClassesHasSubKeys(ByVal sKeyName As String) As Boolean
   Dim lRetval As Long
   Dim subkeys As Long
   Dim hKey As Long         'handle of opened key
   Dim ft As FILETIME
   Dim Class As String
   Dim cbClass As Long
   Dim cbMaxSubKeyLen As Long
   Dim cbMaxClassLen As Long
   Dim cValues As Long
   Dim cbMaxValueNameLen As Long
   Dim cbMaxValueLen As Long
   Dim cbSecurityDescriptor As Long
   
   RegClassesHasSubKeys = False
   lRetval = RegOpenKeyEx(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_ALL_ACCESS, hKey)
   If (lRetval = 0) Then
      lRetval = RegQueryInfoKey(hKey, Class, cbClass, ByVal 0, subkeys, cbMaxSubKeyLen, cbMaxClassLen, _
                                cValues, cbMaxValueNameLen, cbMaxValueLen, cbSecurityDescriptor, ft)
      If (lRetval = 0) And subkeys > 0 Then
         RegClassesHasSubKeys = True
      Else
         RegClassesHasSubKeys = False
      End If
       RegCloseKey hKey
   End If
End Function


0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now