Link to home
Start Free TrialLog in
Avatar of mojo_4664
mojo_4664

asked on

Using VBScript to Add More Than Two WINS Servers

Okay, pretty straightforward question here:

When manually adding WINS server entries to any given network connection, you can add as many as you want. However, when using VBScript the SetWINSServer function will only accept two strings (primary and secondary only).

I would like to add three for additional redundancy. Is this possible to do through VBScript?

Thanks in advance,
Lance
ASKER CERTIFIED SOLUTION
Avatar of graye
graye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mojo_4664
mojo_4664

ASKER

Awesome, that pointed me in the right direction. Here's the final code for anyone that's interested (It's been edited to only contain the stuff about setting the WINS addresses):

Sub SetStaticIP
    Const DISCONNECTED = 0
    Const CONNECTED = 2

    Dim objNetworkSettings, objWMIService
    Dim colNetCards, objNetCard
    Dim strNetCardCaption, colItems, objItem

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

    Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")

    Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter where AdapterType = 'Ethernet 802.3'",,48)

    For Each objItem in colItems
        Dim errEnable

        Set colNetCards = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled = True and Caption = '" & objItem.Caption & "'",,48)

        ' NetConnectionStatus only works on XP!!!
        If objItem.NetConnectionStatus = CONNECTED Then
            For Each objNetCard in colNetCards
                Dim oReg
                Dim strSettingID, strKeyPath, MultValueName, Return

                ' Set WINS addresses
                strSettingID = objNetCard.SettingID
                const HKEY_LOCAL_MACHINE = &H80000002
                strKeyPath = "SYSTEM\CurrentControlSet\Services\NetBT\Parameters\Interfaces\Tcpip_" & strSettingID
                MultValueName = "NameServerList"

                Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
                   strComputer & "\root\default:StdRegProv")

                Return = oReg.SetMultiStringValue(HKEY_LOCAL_MACHINE, strKeyPath, MultValueName, arrWINSServers)
                If (Return <> 0) Or (Err.Number <> 0) Then
                    Wscript.Echo "Could not set the value of HKEY_LOCAL_MACHINE\" & strKeyPath & "\" & MultValueName & " (Error = " & Err.Number & ")."
                End If
            Next
        Else
            For Each objNetCard in colNetCards
                ...
            Next
        End If
    Next
End Sub