wookie7
asked on
MaxMTU Registry Question
I'm trying to figure out how to query for the MaxMTU in the Registry under HKEY_LOCAL_MACHINE System\CurrentControlSet\S ervices\Cl ass\NetTra ns\
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!
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!
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.
ASKER
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.
ASKER
Adjusted points to 105
HMM, 5 additional points.
Bindings can be found in HKEY_LOCAL_MACHINE\Enum\Ne twork
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.
Bindings can be found in HKEY_LOCAL_MACHINE\Enum\Ne
Here you will find all the Network clients/protocols/services
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.
HMM, 5 additional points.
Bindings can be found in HKEY_LOCAL_MACHINE\Enum\Ne twork
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.
Bindings can be found in HKEY_LOCAL_MACHINE\Enum\Ne
Here you will find all the Network clients/protocols/services
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.
ASKER
Hehe ok you have any idea of how im gonna do that?
ASKER
Hehe ok you have any idea of how im gonna do that?
How do you mean? Do you want me to write it for you or do you need functions to access the registry?
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(lhKe y, 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(lPredefined Key, 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
'@@@@@@@@ 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,
If lrc <> ERROR_NONE Then Error 5
Select Case lType
' For strings
Case REG_SZ:
sValue = String(cch, 0)
lrc = RegQueryValueExString(lhKe
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,
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",
'
' 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(lPredefined
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_
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_
KEY_ALL_ACCESS, hKey)
lRetVal = QueryValueEx(hKey, sValueName, vValue)
MsgBox vValue ' vValue stores the returned value
RegCloseKey (hKey)
End Sub
I should note that the above code is taken straight from the knowledge base
Yeh, and also note that the above code does not do enumeration.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did you also ask the question to retrieve this registry entry for 750?