Part 6: Scripting WINS on Clients
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.
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.
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.
Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to “impersonate.”
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.
For each network adapter configuration in the collection, perform the following tasks.
Assign the Win32_NetworkAdapterConfiguration properties DNSHostName to a variable.
Use a Select Case statement to convert the values of the TcpipNetbiosOptions property to descriptive strings.
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.
On each succeeding iteration through another network adapter, concatenate the strings for that adapter onto the original string.
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 |
|
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
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.
Define constants to represent the three possible values of the TcpipNetbiosOptions property.
Create a variable to specify the computer name.
Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to “impersonate.”
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.
Display the name of the computer.
For each network adapter configuration in the collection, perform the following tasks.
Display the Index property of the network adapter.
Call the SetTCPIPNetBIOS method of Win32_NetworkAdapterConfiguration, passing it as the single parameter one of the three constants representing values of the TcpipNetbiosOptions property.
Check the value returned by the method, and display a success or error message.
Requery Win32_NetworkAdapterConfiguration.
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 |
|
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
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.
Create a variable to specify the computer name.
Create variables to specify the four parameters to be passed to the EnableWINS method.
Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to “impersonate.”
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.
Display the name of the computer.
Call the static method EnableWINS of Win32_NetworkAdapterConfiguration, passing it the four parameters defined above.
Check the value returned by the method, and display a success or error message.
Use the ExecQuery method to requery the Win32_NetworkAdapterConfiguration class, filtering the WQL query with “WHERE IPEnabled = True.”
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 |
|
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
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).
Create a variable to specify the computer name.
Create two variables to specify the IP addresses of the primary and secondary WINS servers, to be passed to the EnableWINS method.
Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to “impersonate.”
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.
Display the name of the computer.
Call the static method SetWINSServer of Win32_NetworkAdapterConfiguration, passing it the two parameters defined above.
Check the value returned by the method, and display a success or error message.
Use the ExecQuery method to requery the Win32_NetworkAdapterConfiguration class, filtering the WQL query with “WHERE IPEnabled = True.”
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 |
|
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
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.
Define constants to represent the three possible values of the TcpipNetbiosOptions property.
Create a variable to specify the computer name.
Create variables to specify the parameters to be passed to the EnableWINS method.
Create variables to specify the IP addresses of the primary and secondary WINS servers to be passed to the EnableWINS method.
Initialize two Boolean flag variables to False.
Connect to the WMI service.
Call the GetSettings subroutine, which retrieves current NetBIOS and WINS settings.
Call the SetNetbios function, which sets the NetBIOS over TCP/IP mode to the value specified in the intNetbiosTcpipSet variable.
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.
After making any changes in NetBIOS or WINS settings, again call the GetSettings subroutine.
The GetSettings subroutine retrieves and displays the values for all NetBIOS or WINS settings.
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.
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 |
|
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
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 |
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBIOS |
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters |