Export (0) Print
Expand All

Part 6: Scripting WINS on Clients

Published: July 12, 2004

Although Windows Internet Name Service (WINS) is provided on Windows XP and Windows Server 2003 mainly for backward compatibility with older NetBIOS-based versions of Windows and network applications, WINS is still in wide use as the name resolution system for NetBIOS names. Figure 12 shows the WINS tab of the Advanced TCP/IP Settings dialog box, which provides access to these settings by means of the Windows interface.

06ATNC01.gif

Figure 12   Setting NetBIOS Name Resolution by Using the Windows Interface

For scripts that use WMI, the Win32_NetworkAdapterConfiguration class provides functionality to manage WINS configuration that is comparable to that offered for managing DNS.

If your network uses both WINS and DNS, WINS can use DNS as a backup for name resolution, and vice versa. When you enable WINS by using Win32_NetworkAdapterConfiguration, one of the parameters passed to the EnableWINS method can configure WINS to query the DNS server for names that it cannot resolve during NetBIOS name resolution.

Win32_NetworkAdapterConfiguration also offers a method that can enable or disable the default operation of NetBIOS over TCP/IP, and if DHCP is used, can configure a client to get NetBIOS settings from DHCP. Table 19 describes the WINS properties for the Win32_NetworkAdapterConfiguration class.

Table 19   WINS Properties for the Win32_NetworkAdapterConfiguration Class

Property

Type

Description

DNSEnabledForWINSResolution

Boolean

If TRUE, the DNS is enabled for name resolution over WINS resolution. If the name cannot be resolved using DNS, the name request is forwarded to WINS for resolution.

TcpipNetbiosOptions

New for Windows XP

Uint32

Bitmap of the possible settings related to NetBIOSover TCP/IP. Values are as follows:

0 = Enable NetBIOS via DHCP

1 = Enable NetBIOS

2 = Disable NetBIOS

WINSEnableLMHostsLookup

Boolean

If TRUE, local lookup files are used. Lookup files will contain a map of IP addresses to host names. If they exist on the local system, they will be found in %systemroot%\System32\Drivers\etc.

WINSHostLookupFile

String

Path to a WINS lookup file on the local system. This file will contain a map of IP addresses to host names. If the file specified in this property is found, it will be copied to the %systemroot%\System32\Drivers\etc folder of the local system. Valid only if the WINSEnableLMHostsLookup property is TRUE.

WINSPrimaryServer

String

IP address for the primary WINS server.

WINSScopeID

String

Value appended to the end of the NetBIOS name that isolates a group of computer systems communicating with only each other. It is used for all NetBIOS transactions over TCP/IP communications from that computer system. Computers configured with identical scope identifiers are able to communicate with this computer. TCP/IP clients with different scope identifiers disregard packets from computers with this scope identifier. Valid only when the EnableWINS method executes successfully.

WINSSecondaryServer

String

IP address for the secondary WINS server.


All the properties in the previous table are read-only.

Table 20 describes the WINS methods for the Win32_NetworkAdapterConfiguration class.

Table 20   WINS Methods for the Win32_NetworkAdapterConfiguration Class

Method

Parameters

Description

EnableWINS

DNSEnabledForWINSResolution - Boolean

WINSEnableLMHostsLookup – Boolean

WINSHostLookupFile –string

WINSScopeID - string

Static method. Enables WINS settings specific to TCP/IP, but independent of the network adapter.

SetWINSServer

WINSPrimaryServer – string

WINSSecondaryServer – string

Static method. Sets the primary and secondary WINS servers on this TCP/IP-bound network adapter. This method is applied independently of the network adapter.


All the methods in the previous table return a positive integer:

  • 0 indicates successful completion.

  • 1 indicates successful completion with reboot required.

  • Numbers greater than 1 indicate that some problem was encountered and the method could not complete. The WMI SDK lists the meanings of return values for these methods.

This section provides scripting steps and sample scripts for these WINS-related tasks:

  • Displaying WINS client information

  • Enabling NETBIOS.

  • Enabling WINS.

  • Setting WINS servers for a client.

Displaying WINS Client Information

In managing WINS on clients, as with DHCP and DNS, the first step is usually to determine current settings. This section demonstrates how to retrieve current NetBIOS and WINS settings.

Scripting Steps

Listing 39 displays the WINS client settings for each network adapter configuration on a computer.

  1. Create a variable and assign the name of a computer to it. For the local computer, simply specify "." as the computer name. To run this script remotely, specify the name of an accessible remote computer on your network on which you have administrative privileges. The name can be in the form of either a host name or an IP address.

  2. Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to “impersonate.”

  3. Use the ExecQuery method to query the Win32_NetworkAdapterConfiguration class, filtering the WQL query with “WHERE IPEnabled = True.”

    This returns a collection consisting of all the network adapter configurations on the computer for which IP is enabled.

  4. For each network adapter configuration in the collection, perform the following tasks.

  5. Assign the Win32_NetworkAdapterConfiguration properties DNSHostName to a variable.

  6. Use a Select Case statement to convert the values of the TcpipNetbiosOptions property to descriptive strings.

  7. Concatenate labels, the descriptive string for the TcpipNetbiosOptions property, and the values for Win32_NetworkAdapterConfiguration properties Index, Description, WINSPrimaryServer, WINSSecondaryServer, WINSScopeID, WINSEnableLMHostsLookup, WINSHostLookupFile and DNSEnabledForWINSResolution into a string.

  8. On each succeeding iteration through another network adapter, concatenate the strings for that adapter onto the original string.

  9. Display the host name and the settings for each adapter.

Listing 39   Winssettings.vbs

  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39


On Error Resume Next
 
strComputer = "."
 
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNicConfigs = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
For Each objNicConfig In colNicConfigs
  strDNSHostName = objNicConfig.DNSHostName
  intNetBIOS = objNicConfig.TcpipNetbiosOptions
  Select Case intNetBIOS
    Case 0 strNetBIOS = "Use NetBIOS setting from the DHCP server."
    Case 1 strNetBIOS = "Enable NetBIOS over TCP/IP."
    Case 2 strNetBIOS = "Disable NetBIOS over TCP/IP."
    Case Else strNetBIOS = "Unable to determine setting for NetBIOS " & _
     "Over TCP/IP."
  End Select
  strWINSSettings = strWINSSettings & VbCrLf & VbCrLf & _
   "  Network Adapter " & objNicConfig.Index & VbCrLf & _
   "    " & objNicConfig.Description & VbCrLf & VbCrLf & _
   "    NetBIOS: " & strNetBIOS & VbCrLf & _
   "    WINS Primary Server:             " & _
   objNicConfig.WINSPrimaryServer & VbCrLf & _
   "    WINS Secondary Server:           " & _
   objNicConfig.WINSSecondaryServer & VbCrLf & _
   "    WINS Scope ID:                   " & _
   objNicConfig.WINSScopeID & VbCrLf & _
   "    WINS Enable LMHosts Lookup:      " & _
   objNicConfig.WINSEnableLMHostsLookup & VbCrLf & _
   "    WINS Host Lookup File:           " & _
   objNicConfig.WINSHostLookupFile & VbCrLf & _
   "    DNS Enabled For WINS Resolution: " & _
   objNicConfig.DNSEnabledForWINSResolution
Next
 
WScript.Echo VbCrLf & "WINS Settings" & VbCrLf & VbCrLf & _
 "Host Name: " & strDNSHostName & strWINSSettings



When you use Cscript.exe to run this script, output similar to the following is displayed in the command window:

C:\scripts>winssettings.vbs

 

WINS Settings

 

Host Name: client1

 

  Network Adapter 1

    3Com 3C920 Integrated Fast Ethernet Controller (3C905C-TX Compatible) - Pack

et Scheduler Miniport

 

    NetBIOS: Enable NetBIOS over TCP/IP.

    WINS Primary Server:

    WINS Secondary Server:

    WINS Scope ID:

    WINS Enable LMHosts Lookup:      True

    WINS Host Lookup File:

    DNS Enabled For WINS Resolution: False

Enabling NetBIOS

Because WINS resolves NetBIOS names, you must enable NetBIOS when you enable WINS on a client. When DHCP is enabled, the client can obtain NetBIOS settings from the DHCP server. Otherwise, when a client is using a static IP address, you must configure WINS settings on that client.

The setting for NetBIOS over TCP/IP is exposed in the Windows interface by the three radio buttons at the bottom of the WINS tab of the Advanced TCP/IP settings dialog box (see Figure 12).

Table 21 shows how these radio buttons correspond to the three possible values of the TcpipNetbiosOptions property of Win32_Network AdapterConfiguration, which you can set by using the SetTCPIPNetBIOS() method.

Table 21   Values of the TcpipNetbiosOptions Property

Value

Meaning

Use

0

Enable NetBIOS by means of DHCP

When DHCP is enabled in order to obtain NetBIOS settings from the DHCP server. If a static IP address is used or the DHCP server does not provide a NetBIOS setting, this setting enables NetBIOS over TCP/IP.

1

Enable NetBIOS

When static IP addressing is enabled and DHCP is disabled.

2

Disable NetBIOS

When NetBIOS is not being used on the network.


Scripting Steps

caution.gif  Caution
This script may make changes in your computer configuration. Run it only on a test computer and note the settings involved before running it.

Listing 40 enables NetBIOS on a network adapter. It uses the SetTCPIPNetBIOS() method of the Win32_NetworkAdapterConfiguration class to set the TcpipNetbiosOptions property. This property is new for Windows XP.

  1. Define constants to represent the three possible values of the TcpipNetbiosOptions property.

  2. Create a variable to specify the computer name.

  3. Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to “impersonate.”

  4. Use the ExecQuery method to query the Win32_NetworkAdapterConfiguration class, filtering the WQL query with “WHERE IPEnabled = True.”

    This returns a collection consisting of all the network adapter configurations on the computer for which IP is enabled.

  5. Display the name of the computer.

  6. For each network adapter configuration in the collection, perform the following tasks.

  7. Display the Index property of the network adapter.

  8. Call the SetTCPIPNetBIOS method of Win32_NetworkAdapterConfiguration, passing it as the single parameter one of the three constants representing values of the TcpipNetbiosOptions property.

  9. Check the value returned by the method, and display a success or error message.

  10. Requery Win32_NetworkAdapterConfiguration.

  11. Display the new TcpipNetbiosOptions property, using a Select Case statement to convert the integer value into an explanatory string.

Listing 40   Wins-enablenetbios.vbs

  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45


On Error Resume Next
 
Const ENABLE_NETBIOS_VIA_DHCP = 0
Const ENABLE_NETBIOS = 1
Const DISABLE_NETBIOS = 2
strComputer = "."
 
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNicConfigs = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
WScript.Echo VbCrLf & "Host Name: " & strComputer
For Each objNicConfig in colNicConfigs
  WScript.Echo VbCrLf & "  Network Adapter " & objNicConfig.Index & _
   "    " & objNicConfig.Description & VbCrLf & _
  "    Attempting to set NetBIOS over TCP/IP default."
  intNetBIOS = objNicConfig.SetTCPIPNetBIOS(ENABLE_NETBIOS_VIA_DHCP)
  If intNetBIOS = 0 Then
    WScript.Echo "    Successfully set NetBIOS over TCP/IP default."
  ElseIf intNetBIOS = 1 Then
    WScript.Echo "    Successfully set NetBIOS over TCP/IP default." & _
     VbCrLf & "    Must reboot."
  Else
    WScript.Echo "    Unable to set NetBIOS default."
  End If
Next
 
WScript.Echo VbCrLf & String(80, "-")
 
Set colNicConfigs = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
For Each objNicConfig In colNicConfigs
  WScript.Echo VbCrLf & _
   "  Network Adapter " & objNicConfig.Index & VbCrLf & _
   "    " & objNicConfig.Description
  intNetBIOS = objNicConfig.TcpipNetbiosOptions
  Select Case intNetBIOS
    Case 0 strNetBIOS = "Use NetBIOS setting from the DHCP server"
    Case 1 strNetBIOS = "Enable NetBIOS over TCP/IP"
    Case 2 strNetBIOS = "Disable NetBIOS over TCP/IP"
  End Select
  WScript.Echo "    NetBIOS Over TCP/IP: " & strNetBIOS
Next



When you use Cscript.exe to run this script, output similar to the following is displayed in the command window:

C:\scripts>wins-enablenetbios.vbs

 

Host Name: .

 

  Network Adapter 1    3Com 3C920 Integrated Fast Ethernet Controller (3C905C-TX

Compatible) - Packet Scheduler Miniport

    Attempting to set NetBIOS over TCP/IP default.

    Successfully set NetBIOS over TCP/IP default.

 

--------------------------------------------------------------------------------

 

  Network Adapter 1

    3Com 3C920 Integrated Fast Ethernet Controller (3C905C-TX Compatible) - Pack

et Scheduler Miniport

    NetBIOS Over TCP/IP: Enable NetBIOS over TCP/IP

Enabling WINS

If NetBIOS is enabled through DHCP, you need not enable WINS or assign WINS servers manually because the client gets these settings from the DHCP server. However, if NetBIOS is enabled independently of DHCP, you must enable WINS and assign IP addresses for a primary server and optionally, for a secondary WINS server.

Win32_NetworkAdapterConfiguration offers two methods to accomplish this: one that enables WINS and configures four WINS settings; another that assigns primary and secondary WINS servers.

Scripting Steps

caution.gif  Caution
This script may make changes in your computer configuration. Run it only on a test computer and note the settings involved before running it.

Listing 41 enables WINS and sets four parameters that are passed to the EnableWINS method. Table 22 describes the parameters of the EnableWINS method.

Table 22   Parameters of the EnableWINS Method

Parameter

Type

Description

DNSEnabledForWINSResolution

Boolean

A value indicating whether to enable DNS as the backup method for name resolution.

WINSEnableLMHostsLookup

Boolean

A value indicating whether to enable the use of the LMHOSTS lookup file to map NetBIOS names to IP addresses.

WINSHostLookupFile

String

The path to the LMHOSTS lookup file. This parameter is optional and is used only if the previous value (WINSEnableLMHostsLookup) is True.

WINSScopeID

String

the scope identifier to be appended to the end of the computer's NetBIOS name. Computers that use the same scope identifier can communicate with each other.


The name of each parameter is also the name of the property that can be used to retrieve the value.

EnableWINS is a static method that applies to all instances of the class, which in this case means all network adapters.

  1. Create a variable to specify the computer name.

  2. Create variables to specify the four parameters to be passed to the EnableWINS method.

  3. Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to “impersonate.”

  4. Call the Get method on the Win32_NetworkAdapterConfiguration class.

    This returns an object reference to the Win32_NetworkAdapterConfiguration class itself, rather than a collection of its instances. This reference to the class must be used to call the static method EnableWINS.

  5. Display the name of the computer.

  6. Call the static method EnableWINS of Win32_NetworkAdapterConfiguration, passing it the four parameters defined above.

  7. Check the value returned by the method, and display a success or error message.

  8. Use the ExecQuery method to requery the Win32_NetworkAdapterConfiguration class, filtering the WQL query with “WHERE IPEnabled = True.”

  9. Display the settings that have been configured with the EnableWINS method.

Listing 41   Wins-enable.vbs

  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42


On Error Resume Next
 
strComputer = "."
blnDNSEnabledForWINSResolution = True
blnWINSEnableLMHostsLookup = True
strWINSHostLookupFile = ""
strWINSScopeID = "WORKGROUP"
 
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNicConf = objWMIService.Get("Win32_NetworkAdapterConfiguration")
 
WScript.Echo VbCrLf & "Host Name: " & strComputer & VbCrLf & _
 "  Attempting to enable WINS"
intEnableWINS = objNicConf.EnableWINS(blnDNSEnabledForWINSResolution, _
 blnWINSEnableLMHostsLookup, strWINSHostLookupFile, strWINSScopeID)
If intEnableWINS = 0 Then
  WScript.Echo "    Successfully enabled WINS on all network adapters."
ElseIf intEnableWINS = 1 Then
  WScript.Echo "    Successfully enabled WINS on all network adapters." & _
   VbCrLf & "    Must reboot."
Else
  WScript.Echo "    Unable to enable WINS."
End If
 
WScript.Echo VbCrLf & String(80, "-")
 
Set colNicConfigs = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
For Each objNicConfig In colNicConfigs
  WScript.Echo VbCrLf & _
   "  Network Adapter " & objNicConfig.Index & VbCrLf & _
   "    " & objNicConfig.Description
  WScript.Echo "    DNS Enabled For WINS Resolution: " & _
   objNicConfig.DNSEnabledForWINSResolution
  WScript.Echo "    WINS Enable LMHosts Lookup: " & _
   objNicConfig.WINSEnableLMHostsLookup
  WScript.Echo "    WINS Host Lookup File: " & _
   objNicConfig.WINSHostLookupFile
  WScript.Echo "    WINS Scope ID: " & objNicConfig.WINSScopeID
Next



When you use Cscript.exe to run this script, output similar to the following is displayed in the command window:

C:\scripts>wins-enable.vbs

 

Host Name: .

  Attempting to enable WINS

    Successfully enabled WINS on all network adapters.

 

--------------------------------------------------------------------------------

 

 

  Network Adapter 1

    3Com 3C920 Integrated Fast Ethernet Controller (3C905C-TX Compatible) - Pack

et Scheduler Miniport

    DNS Enabled For WINS Resolution: True

    WINS Enable LMHosts Lookup: True

    WINS Host Lookup File:

    WINS Scope ID: WORKGROUP

Setting WINS Servers for a Client

If NetBIOS is enabled independently of DHCP, you must assign IP addresses for a primary server and optionally, for a secondary WINS server, as well as enabling WINS.

Win32_NetworkAdapterConfiguration offers the SetWINSServer method to assign WINS servers to a client.

Scripting Steps

caution.gif  Caution
This script may make changes in your computer configuration. Run it only on a test computer and note the settings involved before running it.

Listing 42 assigns primary and secondary WINS servers to a client.

SetWINSServer is a static method, which means that it applies to all instances of the class (in this case, all network adapters).

  1. Create a variable to specify the computer name.

  2. Create two variables to specify the IP addresses of the primary and secondary WINS servers, to be passed to the EnableWINS method.

  3. Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to “impersonate.”

  4. Call the Get method on the Win32_NetworkAdapterConfiguration class.

    This returns an object reference to the Win32_NetworkAdapterConfiguration class itself, rather than a collection of its instances. This reference to the class must be used to call the static method SetWINSServer.

  5. Display the name of the computer.

  6. Call the static method SetWINSServer of Win32_NetworkAdapterConfiguration, passing it the two parameters defined above.

  7. Check the value returned by the method, and display a success or error message.

  8. Use the ExecQuery method to requery the Win32_NetworkAdapterConfiguration class, filtering the WQL query with “WHERE IPEnabled = True.”

  9. Display the IP addresses of the WINS servers that have been configured with the SetWINSServer method.

Listing 42   Wins-setservers.vbs

  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43


On Error Resume Next
 
strComputer = "."
strWINSPrimaryServer = "192.168.0.1"
strWINSSecondaryServer = "192.168.0.2"
 
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNicConfigs = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
WScript.Echo VbCrLf & "Host Name: " & strComputer & VbCrLf & _
 "  Attempting to set WINS primary and secondary servers ..."
 
For Each objNicConfig In colNicConfigs
  WScript.Echo VbCrLf & _
   "  Network Adapter " & objNicConfig.Index & VbCrLf & _
   "    " & objNicConfig.Description
  intSetWINSServer = objNicConfig.SetWINSServer(strWINSPrimaryServer, _
   strWINSSecondaryServer)
  If intSetWINSServer = 0 Then
    WScript.Echo "    Successfully set WINS servers."
  ElseIf intSetWINSServer = 1 Then
    WScript.Echo "    Successfully set WINS servers." & _
     VbCrLf & "    Must reboot."
  Else
    WScript.Echo "    Unable to set WINS servers."
  End If
Next
 
WScript.Echo VbCrLf & String(80, "-")
 
Set colNicConfigs = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
For Each objNicConfig In colNicConfigs
  WScript.Echo VbCrLf & _
   "  Network Adapter " & objNicConfig.Index & VbCrLf & _
   "    " & objNicConfig.Description
  WScript.Echo "    Primary WINS Server: " & objNicConfig.WINSPrimaryServer
  WScript.Echo "    Secondary WINS Server: " & _
   objNicConfig.WINSSecondaryServer
Next



When you use Cscript.exe to run this script, output similar to the following is displayed in the command window:

C:\scripts>wins-setservers.vbs

 

Host Name: .

  Attempting to set WINS primary and secondary servers ...

 

  Network Adapter 1

    3Com 3C920 Integrated Fast Ethernet Controller (3C905C-TX Compatible) - Pack

et Scheduler Miniport

    Successfully set WINS servers.

 

--------------------------------------------------------------------------------

 

  Network Adapter 1

    3Com 3C920 Integrated Fast Ethernet Controller (3C905C-TX Compatible) - Pack

et Scheduler Miniport

    Primary WINS Server: 192.168.0.1

    Secondary WINS Server: 192.168.0.2

Scenario: Preparing a Client for WINS

To configure WINS on a client, you must first decide whether and how NetBIOS is to be enabled. If NetBIOS is disabled, you cannot use WINS. If NetBIOS is enabled by means of DHCP, the client can get the correct settings from the DHCP server. If NetBIOS is enabled independent of DHCP, however, you must enable WINS and assign primary and secondary WINS servers.

You can easily expand this script to run against multiple clients by using techniques demonstrated in the "Scripting Remote Network Management" section of this paper.

Scripting Steps

caution.gif  Caution
This script may make changes in your computer configuration. Run it only on a test computer and note the settings involved before running it.

Listing 43 allows you to configure settings for NetBIOS and WINS in a change block near the beginning. It first sets the mode of NetBIOS over TCP/IP on each network adapter. Then, if NetBIOS is enabled but not by means of DHCP, the script enables WINS, configures WINS settings, and sets the IP addresses of the WINS servers for the client to use.

  1. Define constants to represent the three possible values of the TcpipNetbiosOptions property.

  2. Create a variable to specify the computer name.

  3. Create variables to specify the parameters to be passed to the EnableWINS method.

  4. Create variables to specify the IP addresses of the primary and secondary WINS servers to be passed to the EnableWINS method.

  5. Initialize two Boolean flag variables to False.

  6. Connect to the WMI service.

  7. Call the GetSettings subroutine, which retrieves current NetBIOS and WINS settings.

  8. Call the SetNetbios function, which sets the NetBIOS over TCP/IP mode to the value specified in the intNetbiosTcpipSet variable.

  9. If the resulting NetBIOS over TCP/IP setting is ENABLE_NETBIOS, call the SetWins function.

    If it is ENABLE_NETBIOS_VIA_DHCP or DISABLE_NETBIOS, the script does not configure WINS settings.

  10. After making any changes in NetBIOS or WINS settings, again call the GetSettings subroutine.

  11. The GetSettings subroutine retrieves and displays the values for all NetBIOS or WINS settings.

  12. The SetNetbios function checks the current setting of the TcpipNetbiosOptions property. If the property is not the same as the setting specified in the intNetbiosTcpipSet variable, SetNetbios changes the setting to the value of intNetbiosTcpipSet. The function returns a value of True if the NetBIOS over TCP/IP value has been set, and False if the value was not set.

  13. The SetWins function first calls the EnableWINS method, using the parameters specified in the variables set at the beginning of the script. The function then calls the SetWINSServer method with parameters specifying the IP addresses of the primary and secondary WINS servers. The function returns a value of True if both EnableWINS and SetWINSServer returned a value of 0, and False if either method returned a value other than 0.

Listing 43   Wins-client.vbs

  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171


On Error Resume Next
 
Const ENABLE_NETBIOS_VIA_DHCP = 0
Const ENABLE_NETBIOS = 1
Const DISABLE_NETBIOS = 2
 
strComputer = "."
blnDNSEnabledForWINSResolution = True
blnWINSEnableLMHostsLookup = True
strWINSHostLookupFile = ""
strWINSScopeID = "WORKGROUP"
strWINSPrimaryServer = "192.168.0.1"
strWINSSecondaryServer = "192.168.0.2"
intNetbiosTcpipSet = ENABLE_NETBIOS
blnNetbiosSet = False
blnWinsSet = False
 
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
WScript.Echo VbCrLf & "Host Name: " & strComputer
 
WScript.Echo VbCrLf & "NetBIOS and WINS settings before:"
 
GetSettings
 
WScript.Echo VbCrLf & String(80, "-")
 
blnNetbiosSet = SetNetbios
If blnNetbiosSet = True Then
  Select Case intNetbiosTcpipSet
    Case 0
      WScript.Echo VbCrLf & "  NetBIOS settings obtained from the DHCP " & _
       "server." & VbCrLf & "  WINS parameters not set."
    Case 1
      WScript.Echo VbCrLf & "  NetBIOS over TCP/IP enabled." & _
       VbCrLf & "  Setting WINS parameters ..."
      blnWinsSet = SetWins
      If blnWinsSet = True Then
        WScript.Echo VbCrLf & "  All WINS parameters set."
      Else
        WScript.Echo VbCrLf & "  Unable to set all WINS parameters."
      End If
    Case 2
      WScript.Echo VbCrLf & "  NetBIOS over TCP/IP disabled." & _
       VbCrLf & "  WINS parameters not set."
    Case Else
      WScript.Echo VbCrLf & "  Could not determine setting for NetBIOS " & _
       "Over TCP/IP." & VbCrLf & "  WINS parameters not set."
  End Select
Else
  WScript.Echo VbCrLf & "  NetBIOS Over TCP/IP could not be enabled" & _
   VbCrLf & "  WINS parameters not set."
End If
 
WScript.Echo VbCrLf & String(80, "-")
 
WScript.Echo VbCrLf & "NetBIOS and WINS settings after:"
 
GetSettings
 
'******************************************************************************
 
Sub GetSettings
 
  Set colNicConfigs = objWMIService.ExecQuery _
   ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
  For Each objNicConfig In colNicConfigs
    WScript.Echo VbCrLf & "  Network Adapter " & objNicConfig.Index & _
     VbCrLf & "    " & objNicConfig.Description
    intNetBIOS = objNicConfig.TcpipNetbiosOptions
    Select Case intNetBIOS
      Case 0 strNetBIOS = "Use NetBIOS setting from the DHCP server"
      Case 1 strNetBIOS = "Enable NetBIOS over TCP/IP"
      Case 2 strNetBIOS = "Disable NetBIOS over TCP/IP"
    End Select
    WScript.Echo "    NetBIOS Over TCP/IP: " & strNetBIOS
    WScript.Echo "    DNS Enabled For WINS Resolution: " & _
      objNicConfig.DNSEnabledForWINSResolution
    WScript.Echo "    WINS Enable LMHosts Lookup: " & _
      objNicConfig.WINSEnableLMHostsLookup
    WScript.Echo "    WINS Host Lookup File: " & _
      objNicConfig.WINSHostLookupFile
    WScript.Echo "    WINS Scope ID: " & objNicConfig.WINSScopeID
    WScript.Echo "    Primary WINS Server: " & objNicConfig.WINSPrimaryServer
    WScript.Echo "    Secondary WINS Server: " & _
      objNicConfig.WINSSecondaryServer
  Next
 
End Sub
 
'******************************************************************************
 
Function SetNetbios
 
Set colNicConfigs = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
For Each objNicConfig in colNicConfigs
  WScript.Echo VbCrLf & "  Network Adapter " & objNicConfig.Index
  intNetBIOS = objNicConfig.TcpipNetbiosOptions
  If intNetBIOS = intNetbiosTcpipSet Then
    WScript.Echo "    NetBIOS Over TCI/IP already set to desired value."
    SetNetbios = True
  Else
    WScript.Echo "    Attempting to set NetBIOS Over TCI/IP value."
    intNetBIOS = objNicConfig.SetTCPIPNetBIOS(intNetbiosTcpipSet)
    If intNetBIOS = 0 Then
      WScript.Echo "    Successfully set NetBIOS over TCP/IP value."
      SetNetbios = True
    ElseIf intNetBIOS = 1 Then
      WScript.Echo "    Successfully set NetBIOS over TCP/IP value." & _
       VbCrLf & "    Must reboot."
      SetNetbios = True
    Else
      WScript.Echo "    Unable to set NetBIOS Over TCI/IP value."
      SetNetbios = False
    End If
  End If
Next
 
End Function
 
'******************************************************************************
 
Function SetWins
 
WScript.Echo VbCrLf & "  Attempting to enable WINS ..."
 
Set objNicConf = objWMIService.Get("Win32_NetworkAdapterConfiguration")
 
intEnableWINS = objNicConf.EnableWINS(blnDNSEnabledForWINSResolution, _
 blnWINSEnableLMHostsLookup, strWINSHostLookupFile, strWINSScopeID)
If intEnableWINS = 0 Then
  WScript.Echo "    Successfully enabled WINS on all network adapters."
ElseIf intEnableWINS = 1 Then
  WScript.Echo "    Successfully enabled WINS on all network adapters." & _
   VbCrLf & "    Must reboot."
Else
  WScript.Echo "    Unable to enable WINS."
End If
 
WScript.Echo VbCrLf & "  Attempting to set WINS primary and secondary servers ..."
 
Set colNicConfigs = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
For Each objNicConfig in colNicConfigs
  WScript.Echo VbCrLf & "  Network Adapter " & objNicConfig.Index
  intSetWINSServers = objNicConfig.SetWINSServer(strWINSPrimaryServer, _
   strWINSSecondaryServer)
  intSetWINSServersSum =   intSetWINSServersSum +  intSetWINSServers 
  If intSetWINSServers = 0 Then
    WScript.Echo "    Successfully set WINS servers."
  ElseIf intSetWINSServers = 1 Then
    WScript.Echo "    Successfully set WINS servers." & _
     VbCrLf & "    Must reboot."
  Else
    WScript.Echo "    Unable to set WINS servers."
  End If
Next
 
If (intEnableWINS = 0) And (intSetWINSServersSum = 0) Then
  SetWins = True
Else
  SetWins = False
End If
 
End Function



When you use Cscript.exe to run this script, output similar to the following is displayed in the command window:

C:\scripts>wins-client.vbs

 

Host Name: .

 

NetBIOS and WINS settings before:

 

  Network Adapter 1

    3Com 3C920 Integrated Fast Ethernet Controller (3C905C-TX Compatible) - Pack

et Scheduler Miniport

    NetBIOS Over TCP/IP: Disable NetBIOS over TCP/IP

    DNS Enabled For WINS Resolution: True

    WINS Enable LMHosts Lookup: False

    WINS Host Lookup File:

    WINS Scope ID: WORKGROUP

    Primary WINS Server:

    Secondary WINS Server:

 

--------------------------------------------------------------------------------

 

  Network Adapter 1

    Attempting to set NetBIOS Over TCI/IP value.

    Successfully set NetBIOS over TCP/IP value.

 

  NetBIOS over TCP/IP enabled.

  Setting WINS parameters ...

 

  Attempting to enable WINS ...

    Successfully enabled WINS on all network adapters.

 

  Attempting to set WINS primary and secondary servers ...

 

  Network Adapter 1

    Successfully set WINS servers.

 

  All WINS parameters set.

 

--------------------------------------------------------------------------------

 

NetBIOS and WINS settings after:

 

  Network Adapter 1

    3Com 3C920 Integrated Fast Ethernet Controller (3C905C-TX Compatible) - Pack

et Scheduler Miniport

    NetBIOS Over TCP/IP: Enable NetBIOS over TCP/IP

    DNS Enabled For WINS Resolution: True

    WINS Enable LMHosts Lookup: True

    WINS Host Lookup File:

    WINS Scope ID: WORKGROUP

    Primary WINS Server: 192.168.0.1

    Secondary WINS Server: 192.168.0.2

Tools for Scripting WINS on Clients

Table 23 outlines the available Windows tools to use for scripting WINS on clients.

Table 23   Tools for Scripting WINS on Clients

Technology

Tool

Where Available

Command-line tools

Netsh.exe

Windows operating systems1

Command-line tools

NETWINSCONFIG.PL

Windows 2000 Resource Kit

Command-line tools

Wins.dll: WINS Replication Network Monitor Parser

Windows Server 2003 Support Tools

Command-line tools

Winschk.exe

Windows 2000 Resource Kit

Command-line tools

Winscl.exe: WINS Administration Tool

Windows 2000 Resource Kit

WSH

None

 

WMI

Win32_NetworkAdapterConfiguration

 

1 Windows 2000, Windows XP, and Windows Server 2003. May also be present on other versions of Windows.


Table 24 outlines the available registry subkeys to use for scripting WINS on clients.

caution.gif  Caution
Incorrectly editing the registry may severely damage your system. Before making changes to the registry, you should back up any valued data on the computer.

Table 24   Registry Subkeys Related to Scripting WINS on Clients

Registry Subkeys

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces
\Adapter Identifier

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBIOS

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters


Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft