Configure DNS servers (VBScript)

This code can be found in Chapter 1 of Windows Server 2003 Networking Recipes

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' From the book "Windows Server 2003 Networking Recipes"

' This code will configure the local computer
'   with two DNS servers: 192.168.1.151 and 192.168.1.152
' ------ SCRIPT CONFIGURATION ------
strComputer = "."
arrDNSServers = Array("192.168.1.151", "192.168.1.152")
' --------- END CONFIGURATION ------

Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set Nics = objWMIService.ExecQuery _
  ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

For Each Nic In Nics
  intSetDNSServers = Nic.SetDNSServerSearchOrder(arrDNSServers)
  If intSetDNSServers = 0 Then
    WScript.Echo " DNS Servers set!"
  Else
    WScript.Echo " Error setting DNS server info."
  End If
Next

This code has been viewed 2340 times.

New from the creators of TechTasks.com: StatSheet.com