Imports System.Collections.Generic Imports System.ComponentModel Imports System.Data Imports System.Drawing Imports System.Linq Imports System.Text Imports System.Threading.Tasks Imports System.Windows.Forms Imports System.Management Public Class NetworkHelp Public Shared Sub SetNetworkAdapter() Dim inPar As ManagementBaseObject = Nothing Dim outPar As ManagementBaseObject = Nothing Dim mc As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration") Dim moc As ManagementObjectCollection = mc.GetInstances() For Each mo As ManagementObject In moc If Not CBool(mo("IPEnabled")) Then Continue For inPar = mo.GetMethodParameters("EnableStatic") inPar("IPAddress") = New String() {"192.168.1.10"} inPar("SubnetMask") = New String() {"255.255.0.0"} outPar = mo.InvokeMethod("EnableStatic", inPar, Nothing) inPar = mo.GetMethodParameters("SetGateways") inPar("DefaultIPGateway") = New String() {"172.17.123.254"} outPar = mo.InvokeMethod("SetGateways", inPar, Nothing) inPar = mo.GetMethodParameters("SetDNSServerSearchOrder") inPar("DNSServerSearchOrder") = New String() {"114.114.114.114", "202.97.224.69"} outPar = mo.InvokeMethod("SetDNSServerSearchOrder", inPar, Nothing) Exit For Next End Sub Public Shared Sub button2_Click() Dim mc As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration") Dim moc As ManagementObjectCollection = mc.GetInstances() For Each mo As ManagementObject In moc If Not CBool(mo("IPEnabled")) Then Continue For mo.InvokeMethod("SetDNSServerSearchOrder", Nothing) mo.InvokeMethod("EnableStatic", Nothing) mo.InvokeMethod("SetGateways", Nothing) mo.InvokeMethod("EnableDHCP", Nothing) Exit For Next End Sub End Class