L
Larry Powell
I'm attempting to read IP addresses from the registry and have hit a
stumbling block.
While I have no difficulty moving through the registry values finding
strings of the REG_SZ type when I try to get information form the
REG_MULTI_SZ - I get errors.
The following code works just fine. It is from a Windows .NET app
Private Sub Get_StringInfoFromRegistry()
Dim regKey As RegistryKey
Dim strTCPIPAdapterInfoKey As String =
"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces"
Dim strIPAddresses() As String
Dim strNicCards() As String
Dim strIPAddress As String
Dim strNetworkInterface As String
Dim strDomainAddress As String
Dim bFound As Boolean = False
Dim addressinfo As String = "0.0.0.0"
Try
regKey = Registry.LocalMachine.OpenSubKey(strTCPIPAdapterInfoKey)
strNicCards = regKey.GetSubKeyNames
For Each strNetworkInterface In strNicCards
Dim newKey As String = strTCPIPAdapterInfoKey & "\" & strNetworkInterface
If Not bFound Then
regKey = Registry.LocalMachine.OpenSubKey(newKey, False)
'MsgBox(newKey)
If Equals(regKey.GetValue("test".ToString), "Chas") Then
strDomainAddress = regKey.GetValue("Test".ToString)
MsgBox(strDomainAddress)
End If
End If
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
The following code errors when the values are a multi String valued key:
Private Sub Get_StringInfoFromRegistry()
Dim regKey As RegistryKey
Dim strTCPIPAdapterInfoKey As String =
"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces"
Dim strIPAddresses() As String
Dim strNicCards() As String
Dim strIPAddress As String
Dim strNetworkInterface As String
Dim strDomainAddress As String
Dim bFound As Boolean = False
Dim addressinfo As String = "0.0.0.0"
Try
regKey = Registry.LocalMachine.OpenSubKey(strTCPIPAdapterInfoKey)
strNicCards = regKey.GetSubKeyNames
For Each strNetworkInterface In strNicCards
Dim newKey As String = strTCPIPAdapterInfoKey & "\" & strNetworkInterface
If Not bFound Then
regKey = Registry.LocalMachine.OpenSubKey(newKey, False)
'MsgBox(newKey)
If Equals(regKey.GetValue("IPAddress".ToString), "0.0.0.0") Then
strDomainAddress = regKey.GetValue("IPAddress".ToString)
MsgBox(strDomainAddress)
End If
End If
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Any help is appreciated
LP
stumbling block.
While I have no difficulty moving through the registry values finding
strings of the REG_SZ type when I try to get information form the
REG_MULTI_SZ - I get errors.
The following code works just fine. It is from a Windows .NET app
Private Sub Get_StringInfoFromRegistry()
Dim regKey As RegistryKey
Dim strTCPIPAdapterInfoKey As String =
"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces"
Dim strIPAddresses() As String
Dim strNicCards() As String
Dim strIPAddress As String
Dim strNetworkInterface As String
Dim strDomainAddress As String
Dim bFound As Boolean = False
Dim addressinfo As String = "0.0.0.0"
Try
regKey = Registry.LocalMachine.OpenSubKey(strTCPIPAdapterInfoKey)
strNicCards = regKey.GetSubKeyNames
For Each strNetworkInterface In strNicCards
Dim newKey As String = strTCPIPAdapterInfoKey & "\" & strNetworkInterface
If Not bFound Then
regKey = Registry.LocalMachine.OpenSubKey(newKey, False)
'MsgBox(newKey)
If Equals(regKey.GetValue("test".ToString), "Chas") Then
strDomainAddress = regKey.GetValue("Test".ToString)
MsgBox(strDomainAddress)
End If
End If
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
The following code errors when the values are a multi String valued key:
Private Sub Get_StringInfoFromRegistry()
Dim regKey As RegistryKey
Dim strTCPIPAdapterInfoKey As String =
"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces"
Dim strIPAddresses() As String
Dim strNicCards() As String
Dim strIPAddress As String
Dim strNetworkInterface As String
Dim strDomainAddress As String
Dim bFound As Boolean = False
Dim addressinfo As String = "0.0.0.0"
Try
regKey = Registry.LocalMachine.OpenSubKey(strTCPIPAdapterInfoKey)
strNicCards = regKey.GetSubKeyNames
For Each strNetworkInterface In strNicCards
Dim newKey As String = strTCPIPAdapterInfoKey & "\" & strNetworkInterface
If Not bFound Then
regKey = Registry.LocalMachine.OpenSubKey(newKey, False)
'MsgBox(newKey)
If Equals(regKey.GetValue("IPAddress".ToString), "0.0.0.0") Then
strDomainAddress = regKey.GetValue("IPAddress".ToString)
MsgBox(strDomainAddress)
End If
End If
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Any help is appreciated
LP