there is no need to output to a file the current settings, you are only going to need that information again, read back into memory to make your decision?
'please excuse my use of .Writeline with obvious xml, i was forced to write with TS due to other members of the team
'need to run off and get the nic information
Dim colAdapters, objAdapter, strTemp, dicNoDuplicates, strPNPID, strDeviceId, strSubId, objNIC, strNetConnectionStatus
Set dicNoDuplicates = CreateObject("Scripting.Dictionary")
Set colAdapters = objWMIService.ExecQuery("Select * From Win32_NetworkAdapter")
For Each objAdapter In colAdapters
strTemp = ""
If Not IsNull(objAdapter.AdapterType) Then
If CStr(objAdapter.AdapterType) = "Ethernet 802.3" Then
If Not IsNull(objAdapter.MACAddress) Then
strTemp = UCase(objAdapter.MACAddress)
End If
'manipulate objAdapter.PNPDeviceID
strPNPID = "": strDeviceId = "": strSubId = "": strNetConnectionStatus = ""
If Not IsNull(objAdapter.PNPDeviceID) Then
strPNPID = UCase(objAdapter.PNPDeviceID)
If Left(strPNPID, 8) = "PCI\VEN_" Then
strPNPID = Right(strPNPID, Len(strPNPID) - 8)
strDeviceId = Left(strPNPID, 4)
strDeviceId = strDeviceId & Mid(strPNPID, 10, 4)
strSubId = Mid(strPNPID, 22, 8)
End If
End If
'netconnectionstatus?
If Not IsNull(objAdapter.NetConnectionStatus) Then
strNetConnectionStatus = CStr(objAdapter.NetConnectionStatus)
End If
If strTemp <> "" Then
strTemp = Replace(strTemp, ":", "-")
If Not dicNoDuplicates.Exists(strTemp) Then
Set objNIC = New clsNIC
objNIC.MACAddress = strTemp
objNIC.SubId = strSubId
objNIC.DeviceId = strDeviceId
objNIC.NetConnectionStatus = strNetConnectionStatus
'description?
If Not IsNull(objAdapter.Description) Then
objNIC.Description = objAdapter.Description
End If
dicNoDuplicates.Add strTemp, objNIC
Set objNIC = Nothing
End If
End If
End If
End If
Next
Set colAdapters = Nothing
Dim strDNSServers, i
'now lets update the nics in the dicNoDuplicates with the ipstack information
Set colAdapters = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each objAdapter In colAdapters
'MsgBox objAdapter.MACAddress
If dicNoDuplicates.Exists(Replace(CStr(objAdapter.MACAddress), ":", "-")) Then
Set objNIC = dicNoDuplicates.Item(Replace(CStr(objAdapter.MACAddress), ":", "-"))
'ipaddress
If Not IsNull(objAdapter.IPAddress) Then
For i = 0 To UBound(objAdapter.IPAddress)
objNIC.IP = objAdapter.IPAddress(i)
Next
End If
'subnet mask
If Not IsNull(objAdapter.IPSubnet) Then
For i = 0 To UBound(objAdapter.IPSubnet)
'WScript.Echo objAdapter.IPSubnet(i) & " ===="
objNIC.SubNetMask = objAdapter.IPSubnet(i)
Exit For
Next
End If
'default gateway
If Not IsNull(objAdapter.DefaultIPGateway) Then
For i = 0 To UBound(objAdapter.DefaultIPGateway)
objNIC.GateWay = objAdapter.DefaultIPGateway(i)
Next
End If
'dnsservers, they call it the DNSSSO, nice
strDNSServers = ""
If Not IsNull(objAdapter.DNSServerSearchOrder) Then
For i = 0 To UBound(objAdapter.DNSServerSearchOrder)
strDNSServers = strDNSServers & "," & objAdapter.DNSServerSearchOrder(i)
Next
End If
If Left(strDNSServers, 1) = "," Then
strDNSServers = Right(strDNSServers, Len(strDNSServers) - 1)
End If
objNIC.DNS = strDNSServers
objNIC.PrimaryWINS = objAdapter.WINSPrimaryServer
objNIC.SecondaryWINS = objAdapter.WINSSecondaryServer
Set objNIC = Nothing
End If
Next
Set colAdapters = Nothing
For Each objAdapter In dicNoDuplicates
Set objNIC = dicNoDuplicates.Item(objAdapter)
objTS.WriteLine vbTab & vbTab & vbTab & "<nic mac=" & Chr(34) & objAdapter & Chr(34) & " disable=" & Chr(34) & "false" & Chr(34) & " description=" & Chr(34) & objNIC.Description & Chr(34) & ">"
'information which is of interest
objTS.WriteLine vbTab & vbTab & vbTab & vbTab & "<pe_ipaddress>" & objNIC.IP & "</pe_ipaddress>"
'information we might want to keep
objTS.WriteLine vbTab & vbTab & vbTab & vbTab & "<dns>" & objNIC.DNS & "</dns>"
objTS.WriteLine vbTab & vbTab & vbTab & vbTab & "<primarywins>" & objNIC.PrimaryWINS & "</primarywins>"
objTS.WriteLine vbTab & vbTab & vbTab & vbTab & "<secondarywins>" & objNIC.SecondaryWINS & "</secondarywins>"
'information which is of interest
objTS.WriteLine vbTab & vbTab & vbTab & vbTab & "<gateway>" & objNIC.Gateway & "</gateway>"
objTS.WriteLine vbTab & vbTab & vbTab & vbTab & "<subnetmask>" & objNIC.SubNetMask & "</subnetmask>"
'other information which might be of interest
objTS.WriteLine vbTab & vbTab & vbTab & vbTab & "<deviceid>" & objNIC.DeviceId & "</deviceid>"
objTS.WriteLine vbTab & vbTab & vbTab & vbTab & "<subid>" & objNIC.SubId & "</subid>"
objTS.WriteLine vbTab & vbTab & vbTab & vbTab & "<description>" & objNIC.Description & "</description>"
objTS.WriteLine vbTab & vbTab & vbTab & vbTab & "<netconnectionstatus>" & objNIC.NetConnectionStatus & "</netconnectionstatus>"
Set objNIC = Nothing
objTS.WriteLine vbTab & vbTab & vbTab & "</nic>"
Next
objTS.WriteLine vbTab & vbTab & "</nics>"
Class clsNIC
Public IP
Public MACAddress
Public SubNetMask
Public PrimaryWINS
Public SecondaryWINS
Public DNS
Public Gateway
Public DeviceId
Public SubId
Public NetConnectionStatus
Public Description
End Class