Windows Server Hack [Electronic resources]

Mitch Tulloch

نسخه متنی -صفحه : 163/ 66
نمايش فراداده

Hack 40 Change WINS for All Enabled Adapters

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 serversfor example, when you install a new WINS serveryou 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 = "172.16.1.122" 
strWINS2 = "172.16.1.132" 
Set objLocator = CreateObject("WbemScripting.SWbemLocator") 
Set objService = objLocator.ConnectServer(strComputer, "root/cimv2", & strUsername, 
strPassword) 
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" 
Next 
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 10.0.0.15 and your secondary server is 10.0.0.16, change these lines:

strWINS1 = "172.16.1.122" 
strWINS2 = "172.16.1.132"

to this:

strWINS1 = "10.0.0.15" 
strWINS2 = "10.0.0.16"

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