VB Script for changing WINS and DNS on remote machines
![](https://techyv.com/sites/default/2016/10/techpedia_logo.png)
Dear user,
You can copy this code and paste it in your VB project. You will need WMI to use this code:
' IMPORTANT !!!! Change these constants !!!!
Const STR_SERVERS = "server1 server2 "Â ' Enter your servers here, separated by a space
Const STR_NEWDNS1 = "192.168.1.1"
Const STR_NEWDNS2 = "192.168.1.2"
Const STR_NEWWINS1= "192.168.1.3"
Const STR_NEWWINS2= "192.168.1.4"
Â
' ///////////////////////////////////////////////////////////////////////////////////////////////
Do
   cKeuze = MakeChoise( "Choose: Report or Change (R/C)?" )
Loop until cKeuze = "C" Or cKeuze = "R"
WScript.Echo
If( cKeuze = "C" ) Then
   Change( STR_SERVERS )
Else
   Report( STR_SERVERS )
End If
WScript.Echo( "Check out https://www.activexperts.com/ for more samples and components" )
' ///////////////////////////////////////////////////////////////////////////////////////////////
' ///////////////////////////////////////////////////////////////////////////////////////////////
Sub Change( strParamServers )
   arrServers = Split( strParamServers, " " )
   For i = 0 To UBound( arrServers )
      ShowDnsWins arrServers( i )  Â
      Do
         cKeuze = MakeChoise( " Change DNS/WINS and reboot (y/n)?" )
      Loop until cKeuze = "Y" Or cKeuze = "N"  Â
      If( cKeuze = "Y" ) Then
         SetDnsWins arrServers( i )     Â
         RebootServer( arrServers( i ) )
      End If
        Â
      WScript.StdOut.Write( vbCrlf )
   Next
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////
Sub Report( strParamServers )
   arrServers = Split( strParamServers, " " )
   For i = 0 To UBound( arrServers )
      ShowDnsWins arrServers( i )
   Next
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////
Sub ShowDnsWins( strServer )
   strWinMgmt = "winmgmts:{impersonationLevel=impersonate}!//"& strServer &""
   Set objNICs = GetObject( strWinMgmt ).InstancesOf( "Win32_NetworkAdapterConfiguration" )
   WScript.StdOut.Write( strServer & ": " & vbCrlf )
   For Each objNIC In objNICs
      If objNIC.IPEnabled Then
            WScript.StdOut.Write( " " & objNIC.Description & ": " & vbCrlf & "   " )
              n = 1
            For Each strDns In objNIC.DNSServerSearchOrder
               WScript.StdOut.Write "DNS" & n & ":" & strDns & " "
               n = n + 1
            Next
            WScript.StdOut.Write( vbCrlf )
      End If
   Next
   WScript.StdOut.Write( vbCrlf )
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////
Sub SetDnsWins( strServer )
   strWinMgmt = "winmgmts:{impersonationLevel=impersonate}!//"& strServer &""
   Set objNICs = GetObject( strWinMgmt ).InstancesOf( "Win32_NetworkAdapterConfiguration" )
   WScript.StdOut.Write( " Set DNS for NIC: " )
   For Each objNIC In objNICs
      If objNIC.IPEnabled Then
         objNIC.SetWINSServer STR_NEWWINS1,STR_NEWWINS2
         objNIC.SetDNSServerSearchOrder Array(STR_NEWDNS1,STR_NEWDNS2)
         WScript.StdOut.Write objNIC.Description & " "  Â
      End If
   Next
   WScript.StdOut.Write( vbCrlf )
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////
Sub RebootServer( strServer )
   Set OpSysSet = GetObject("winmgmts:{(RemoteShutdown)}//" & strServer & "/root/cimv2").ExecQuery("Select * from Win32_OperatingSystem where Primary=True")
   WScript.StdOut.Write( " Reboot: " )     Â
   For Each OpSys In OpSysSet
      WScript.StdOut.Write OpSys.Name
      OpSys.Reboot()
   Next
   WScript.StdOut.Write( vbCrlf )
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////
Function MakeChoise( strMesg )
   WScript.StdOut.Write(strMesg)
   WScript.StdIn.Read(0)
   strChoise = WScript.StdIn.ReadLine()
   MakeChoise = UCase( Left( strChoise, 1 ) )
End Function
Check out this website for more help:
https://www.activexperts.com/files/vbscript-powershell-component/manual.htm
Hope this will help you.
Thank you.