I'm trying to interact with WMI through a vb.net program in order to make any machine that runs this program pull the IP settings and DNS server settings from DHCP for all network adapters with an IP.
The code I presently have works for DHCP without issue, but does not change DNS settings. The program compiles and executes without issue, but the DNS settings are not changing to be fetched automatically from DHCP.
Dim objMC As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim objMOC As ManagementObjectCollection = objMC.GetInstances()
For Each objMO As ManagementObject In objMOC
If (Not CBool(objMO("IPEnabled"))) Then
Continue For
End If
Try
Dim objNewIP As ManagementBaseObject = Nothing
Dim objSetIP As ManagementBaseObject = Nothing
Dim objNewDNS As ManagementBaseObject = Nothing
Dim objSetDNS As ManagementBaseObject = Nothing
objNewIP = objMO.GetMethodParameters("EnableDHCP")
objSetIP = objMO.InvokeMethod("EnableDHCP", Nothing, Nothing)
objNewDNS = objMO.GetMethodParameters("SetDNSServerSearchOrder")
objSetDNS = objMO.InvokeMethod("SetDNSServerSearchOrder", Nothing, Nothing)
Catch ex As Exception
MessageBox.Show("Settings unchanged : " & ex.Message)
End Try
Next objMO
I'm so close to getting this solved, I just need help to figure out this last step.