2

我在谷歌上搜索时发现了这段代码。我只想将我的 DNS 服务器更改为静态。我只是不知道将我的静态 DNS 和备用 DNS 服务器放在哪里。请帮我。谢谢 :)

Public Sub setDNS(ByVal NIC As String, ByVal DNS As String)
   Dim objMC As New ManagementClass("Win32_NetworkAdapterConfiguration")
   Dim objMOC As ManagementObjectCollection = objMC.GetInstances()

   For Each objMO As ManagementObject In objMOC
      If CBool(objMO("IPEnabled")) Then
         ' if you are using the System.Net.NetworkInformation.NetworkInterface you'll need to change this line to if (objMO["Caption"].ToString().Contains(NIC)) and pass in the Description property instead of the name 
         If objMO("Caption").Equals(NIC) Then
            Try
               Dim newDNS As ManagementBaseObject = objMO.GetMethodParameters("SetDNSServerSearchOrder")
               newDNS("DNSServerSearchOrder") = DNS.Split(","c)
               Dim setDNS As ManagementBaseObject = objMO.InvokeMethod("SetDNSServerSearchOrder", newDNS, Nothing)
            Catch generatedExceptionName As Exception
               Throw
            End Try
         End If
      End If
   Next
End Sub

任何帮助将不胜感激。提前致谢。

4

0 回答 0