Hack 40 Change WINS for All Enabled Adapters

figs/moderate.gif figs/hack40.gif

Changing WINS settings on client machines can be a pain when you have to move your WINS servers. This hack makes it easier.

If you are using WINS as a name-resolution method (typically in a mixed NT/2000 environment) and have to change your WINS servers?for example, when you install a new WINS server?you have to reconfigure WINS settings on all your client computers. If you are using DHCP, you can configure the 044 WINS/NBNS Servers option on your DHCP servers to provide client computers with new WINS servers addresses, but this requires releasing and renewing DHCP leases on all your clients.

Here's another approach you can use. The following script changes the WINS server settings on client machines and is useful when you install new WINS servers and need to change your WINS server settings on workstations across the board. Note that the script also works on multihomed machines (machines that have two or more network adapters).

The Code

Type the following code into Notepad (with Word Wrap disabled) and save it with a .vbs extension as ChangeWINS.vbs:

Option Explicit 

On Error Resume Next 

Dim objLocator, objService, NIC 

Dim strComputer, strUsername, strPassword 

Dim strWINS1, strWINS2 

Dim intErr 

strComputer = "." 

strUsername = "" 

strPassword = "" 

strWINS1 = "" 

strWINS2 = "" 

Set objLocator = CreateObject("WbemScripting.SWbemLocator") 

Set objService = objLocator.ConnectServer(strComputer, "root/cimv2", & strUsername, 


objService.Security_.impersonationlevel = 3 

For Each NIC In objService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration 

Where IPEnabled=True") 

WScript.Echo "Nic Index: " & NIC.index 

WScript.Echo "Current Settings" 

WScript.Echo "Primary Wins Server: " & NIC.WINSPrimaryServer 

WScript.Echo "Secondary Wins Server: " & NIC.WINSSecondaryServer 

intErr = NIC.SetWinsServer(strWINS1, strWINS2) 

If intErr <> 0 Then Wscript.Echo "Error changing WINS" 


Set objService = Nothing 

Set objLocator = Nothing

Running the Hack

To run this hack, you first have to customize it. For example, if your primary WINS server is and your secondary server is, change these lines:

strWINS1 = "" 

strWINS2 = ""

to this:

strWINS1 = "" 

strWINS2 = ""

Then, create a shortcut to the script and double-click on the shortcut to run the script. This will refresh your computer's WINS settings.

?Rod Trent