TechSpot

Batch file script for adding DNS suffixes?

By PCTechie316
Mar 21, 2011
Post New Reply
  1. I tried looking a little on google, and couldnt find much. I need to make a batch file to add dns suffixs to local area connection.

    i have a script that i tested but it didn't work, because i beleive it was for just the 2 local dns's and not for the dns suffixes.

    Any help is a appreciated.

    Update i found a script here. That works for now. Just need to figure out how to set it so it manually checks those 2 boxes.

    On Error Resume Next

    strComputer = "."
    arrDNSDomainSuffixSearchOrder = Array("dns1.com", "dns2.com", "dns3.com")

    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set objNicConf = objWMIService.Get("Win32_NetworkAdapterConfiguration")

    WScript.Echo VbCrLf & "DNS Host Name: " & strDNSHostName & VbCrLf & _
    " Attempting to enable DNS"
    intEnableDNS = objNicConf.EnableDNS(strDNSHostName, strDNSDomain, _
    arrDNSServerSearchOrder, arrDNSDomainSuffixSearchOrder)
    If intEnableDNS = 0 Then
    WScript.Echo " Successfully enabled DNS."
    ElseIf intEnableDNS = 1 Then
    WScript.Echo " Successfully enabled DNS." & VbCrLf & " Must reboot."
    Else
    WScript.Echo " Unable to enable DNS."
    End If

    WScript.Echo VbCrLf & String(80,"-")

    Set colNicConfigs = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

    For Each objNicConfig In colNicConfigs
    strDNSHostName = objNicConfig.DNSHostName
    Next
    WScript.Echo VbCrLf & "DNS Host Name: " & strDNSHostName

    For Each objNicConfig In colNicConfigs
    WScript.Echo VbCrLf & " Network Adapter " & objNicConfig.Index & _
    VbCrLf & " " & objNicConfig.Description
    WScript.Echo " DNS Domain: " & objNicConfig.DNSDomain
    WScript.Echo " DNS Server Search Order:"
    If Not IsNull(objNicConfig.DNSServerSearchOrder) Then
    For Each strDNSServer In objNicConfig.DNSServerSearchOrder
    WScript.Echo " " & strDNSServer
    Next
    End If
    WScript.Echo " DNS Domain Suffix Search Order:"
    If Not IsNull(objNicConfig.DNSServerSearchOrder) Then
    For Each strDNSDomainSuffix In objNicConfig.DNSDomainSuffixSearchOrder
    WScript.Echo " " & strDNSDomainSuffix
    Next
    End If
    Next
     

Similar Topics

Add New Comment

You need to be a member to leave a comment. Join thousands of tech enthusiasts and participate.
TechSpot Account You may also...