Microsoft KB Archive/894564

= How to change the binding order of network adapters in Windows XP and in Windows 2000 =

Article ID: 894564

Article Last Modified on 2/16/2007

-

APPLIES TO


 * Microsoft Windows XP Professional
 * Microsoft Windows XP Professional x64 Edition
 * Microsoft Windows XP Tablet PC Edition
 * Microsoft Windows 2000 Professional Edition
 * Microsoft Windows 2000 Server
 * Microsoft Windows 2000 Advanced Server

-



Important This article contains information about how to modify the registry. Make sure to back up the registry before you modify it. Make sure that you know how to restore the registry if a problem occurs. For more information about how to back up, restore, and modify the registry, click the following article number to view the article in the Microsoft Knowledge Base:

256986 Description of the Microsoft Windows registry



SUMMARY
''You may have several network connections that are connected to different networks. Or, you may have a program that uses the first connection in the network connections list. You may want to make sure that a certain network connection is at the top of the list.

When you install Microsoft Windows XP or Microsoft Windows 2000, the order of the connections may vary depending on how the network adapters are enumerated.

You can use the methods that are described in this article to reorder adapters and bindings and to change the interface metric on the network adapters. This article describes how to perform the following tasks:''


 * Change the binding order of network adapters
 * Change the interface metric on a network adapter
 * Create a fixed metric by changing the InterfaceMetric registry value
 * Set the interface metric by using a script
 * Influence the binding order in Windows XP during unattended setup
 * Change the network provider order



INTRODUCTION
This article describes how to modify the network adapters and the binding order in Microsoft Windows XP and in Microsoft Windows 2000. This article also describes how to change the interface metric on network adapters.



MORE INFORMATION
The following situations are situations in which you may want to change the order of the connections in the list of network adapters and bindings. These situations are also situations in which you might want to change the interface metric on a network adapter.

Note Changing the interface metric on the network adapter gives similar results:
 * The Windows Sockets gethostbyname API is used to retrieve IP addresses that are assigned to a computer. The gethostbyname API returns a list of IP addresses that are assigned to all the network adapters that are installed in the multihomed computer. This list of IP addresses is returned if the host name that is sent in the query is &quot;NULL&quot; or if the host name that is sent by the query is the local host name of the computer.
 * Some third-party device drivers that are installed require that the IP addresses that are returned by the gethostbyname API be listed in a certain order.
 * When a Windows Sockets application calls the gethostbyname API to resolve the local host name to a list of IP addresses on a multihomed computer, the list may be returned in an order that does not match the binding order that is displayed in Control Panel. Or, the list may be returned in an order that does not match the order in which the IP addresses were assigned to the network adapter.
 * You are deploying computers that have a wireless network adapter and a wired network connection. When the computer connects to the wired network, the wireless connection is also enabled. The two connections may cause problems in some programs, and group policies may not work as expected.

Use the methods in this article to resolve or to work around these problems. However, consider the following:
 * There is no unattended way to change the order of the connections during the installation of the network adapter.
 * You cannot programmatically script changes to the binding order of network adapters for a computer that is running.
 * You cannot use Domain Naming System (DNS) to change the order of connections or to change the binding order because DNS does not respect the ordering.

Note This article lists the link speeds and the automatic metrics for computers that run Windows XP and Windows XP Service Pack 2.

How to change the binding order of network adapters

 * 1) Click Start, click Run, type ncpa.cpl, and then click OK.

You can see the available connections in the LAN and High-Speed Internet section of the Network Connections window.
 * 1) On the Advanced menu, click Advanced Settings, and then click the Adapters and Bindings tab.
 * 2) In the Connections area, select the connection that you want to move higher in the list. Use the arrow buttons to move the connection.

Notes
 * 1) * The Adapters and Bindings tab lists the connections in the order in which the connections are accessed by network services. The order of these connections reflects the order in which TCP/IP or the next available protocol is bound to the network adapters. The bindings for remote access connections apply to all remote access connections.
 * 2) * The Provider Order tab lists the network providers for this computer. You can use the arrow buttons to change the order in which these providers are accessed. You can arrange the order in which the computer accesses information about the network. Providers and other connections are accessed in the order in which the providers and the connections are listed.

How to change the interface metric on a network adapter
Warning Serious problems might occur if you modify the registry incorrectly by using Registry Editor or by using another method. These problems might require that you reinstall your operating system. Microsoft cannot guarantee that these problems can be solved. Modify the registry at your own risk. You can change the interface metric on a network adapter if you are using TCP/IP as a transport protocol because TCP/IP uses the interface metric to determine the order. You can change the interface metric to make one network adapter more favorable for all TCP/IP connections. The interface metric (IPConnectionMetric) for a network connection indicates the cost of using the routes in the IP routing table. The routes are derived from the interface configuration. The cost becomes the value in the Metric column for those routes in the IP routing table. If there are multiple routes that are a close match for the route to a destination in the IP routing table, the route that has the lowest metric is used. The range of valid values is 1 through 9999.

To view the IP routing table, type route print at the command prompt. For more information about the Automatic Metric feature that is used in Windows XP for IP routes, click the following article number to view the article in the Microsoft Knowledge Base:

299540 An explanation of the Automatic Metric feature for Internet Protocol routes

To change the interface metric, follow these steps:
 * 1) Click Start, click Run, type ncpa.cpl, and then click OK.

The available connections appear in the LAN and High-Speed Internet section of the Network Connections window.
 * 1) Right-click the network adapter that you want to change, click Properties, and then click the General tab.
 * 2) In the This connection uses the following items box, select Internet Protocol (TCP/IP). Then, click Properties.
 * 3) In the Internet Protocol (TCP/IP) Properties dialog box, click the General tab, and then click Advanced.
 * 4) On the IP Settings tab, click to clear the Automatic metric check box. Then, type a value in the Interface metric box.

Note In Windows 2000, change the value in the Interface metric box from the default value of 1 to a different value. The Automatic metric check box is not present.

How to create a fixed metric by changing the InterfaceMetric registry value
Warning Serious problems might occur if you modify the registry incorrectly by using Registry Editor or by using another method. These problems might require that you reinstall your operating system. Microsoft cannot guarantee that these problems can be solved. Modify the registry at your own risk. You can create a fixed metric in Windows XP or in Windows 2000 without using the route commands. You can create the fixed metric by changing the following registry key and then restarting the computer. When you create the fixed metric, you can configure a specific network adapter to have the lowest metric so that network adapter is used first.

Note The InterfaceMetric registry value is different for each network adapter.

The InterfaceMetric registry value is located in the following registry key:

Configure the registry value as follows:

Name: InterfaceMetric

Type: REG_DWORD

Value Data:

Determining the NetCfgInstanceId value
In this registry key,  is the NetCfgInstanceId value of the network adapter. To determine the NetCfgInstanceId value of the first network adapter, view the following registry subkey:

To determine the NetCfgInstanceId value of the second network adapter, view the following registry subkey:

The penultimate folder is numbered sequentially for all other network adapters. Or, to view all the network adapters that are installed, locate and then expand the following registry subkey:

See the DriverDesc value to identify the network adapter.

In Windows 2000, the InterfaceMetric registry value does not determine the network adapter that is used first. The network adapter that is selected first also depends on the interface initialization order. The interface initialization order frequently is the same from one startup to the next startup. However, the interface initialization order is not guaranteed to be the same for every startup.

In Windows XP and in Windows 2000, set the metric of the preferred network adapter to be lower than the metrics of the other adapters. Setting the metric lower means that the network adapter has a higher priority. The metric takes precedence in the network adapter order. You can set the metric in the TCP/IP properties.

The following information indicates the settings that you must use to set the metric of the preferred network adapter:

Name: DriverDesc

Value Data: 3Com 3C920 Integrated Fast Ethernet Controller (3C905C-TX Compatible)

Name: NetCfgInstanceId

Type: REG_SZ

Value Data: {93396AAE-BCC4-49B4-BCDA-27CC97E9D97F}

Name: InterfaceMetric

Type: REG_DWORD

Sample route metrics and link speeds
Windows XP automatically sets relative route metrics based on link speeds such as the following.

For more information and for an updated table that contains the link speeds and the metrics for Windows XP Service Pack 2-based computers, click the following article number to view the article in the Microsoft Knowledge Base:

299540 An explanation of the Automatic Metric feature for Internet Protocol routes

Windows 2000 does not automatically set relative route metrics. Use the following netsh command to verify the current settings of each active interface. To do this, type the following at the command prompt:

netsh interface ip show address

This command creates output that is similar to the following: Configuration for interface &quot;Local Area Connection&quot; DHCP enabled: Yes InterfaceMetric: 0

Configuration for interface &quot;Wireless Connection&quot; DHCP enabled: Yes InterfaceMetric: 35 Note An InterfaceMetric value of 0 in the output indicates an automatic metric.

For more information about how to modify the IP connection metric for a network adapter, visit the following Microsoft Web site:

http://www.microsoft.com/technet/scriptcenter/scripts/network/client/modify/nwmovb25.mspx

For more information about Microsoft Windows Management Instrumentation (WMI) tasks for networking, visit the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/library/aa394595.aspx

For more information about the Win32_NetworkAdapterConfiguration WMI class, visit the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/library/aa394217.aspx

How to set the interface metric by using a script
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.



The following script uses the Win32_NetworkAdapterConfiguration WMI class. This class represents the attributes and the behavior of a network adapter. This class uses the SetIPConnectionMetric method to set the routing metric that is associated with this IP-bound network adapter for a wireless network connection. This method is a new method for Windows XP.

To use the script, copy the following code to a text file, save the file as &quot;Set_Wireless_NIC_IPMetric.vbs,&quot; and then run the script. ==== snip - Start of script code Set_Wireless_NIC_IPMetric.vbs script ==== On Error Resume Next

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

regValueDataMetric = &quot;35&quot;

Set colItems = objWMIService.ExecQuery _ (&quot;Select * From Win32_NetworkAdapter Where NetConnectionID = 'Wireless Network Connection'&quot;)

For Each objItem in colItems strMACAddress = objItem.MACAddress Wscript.Echo &quot;MACAddress: &quot; & strMACAddress Next

Set colNetCard = objWMIService.ExecQuery _ (&quot;Select * From Win32_NetworkAdapterConfiguration where IPEnabled=TRUE&quot;)

For Each objNetCard in colNetCard If objNetCard.MACAddress = strMACAddress Then For Each strIPAddress in objNetCard.IPAddress Wscript.Echo &quot;Description: &quot; & objNetCard.Description Wscript.Echo &quot;IP Address: &quot; & strIPAddress Wscript.Echo &quot;IPConnectionMetric: &quot; & objNetCard.IPConnectionMetric objNetCard.SetIPConnectionMetric(regValueDataMetric) Next End If Next

How to influence the binding order in Windows XP during unattended setup
You cannot change the connection order during an unattended setup. There also is no programmatic way to change the binding order of network adapters for a computer that is running. This inability to make a change is a problem if you want to programmatically move one local area connection ahead of another local area connection. However, no documented programmatic method exists for changing the order of the adapters.

The sysprep command removes any networking configuration, and the networking configuration is reconfigured when you run the command. Because the sysprep command writes data to many registry settings and files, the sysprep command is difficult to use to force a change in the binding order.

However, if you want to influence the binding order during unattended setup, you can try to specify one network adapter in the Sysprep.inf file. If you specify the local area network (LAN) adapter and then leave the other adapters to be detected after setup by the Plug and Play feature, Windows may put the LAN adapter at the top of the bindings list. For more information about how to disable network bindings, click the following article number to view the article in the Microsoft Knowledge Base:

263241 How to disable network bindings using the [Netbindings] section

The Bindview sample in the Microsoft Windows Driver Development Kit
The Bindview sample in the Microsoft Windows Driver Development Kit (DDK) demonstrates how to use the INetCfg APIs to bind and to unbind a network adapter. These APIs are documented in the Windows DDK. The Bindview sample is located in the following location:

\WINDDK\ \Src\Network\Config\Bindview

Although binding and unbinding a network adapter is not difficult, moving the network adapter binding is a complex task. No API exists that you can use to move a network adapter binding. However, you can write a stand-alone application to move a network adapter binding by using the INetCfg APIs. To do this, you have to enumerate all the bindings for all the components that are installed on the adapters. Then, you have to move the binding path for each binding so that each binding appears before another binding.

For more information about the INetCfg interface, visit the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/library/ms805265.aspx

You can enumerate all the adapters, and you can enumerate anything that is bound to each network adapter. Finally, you can use the INetCfgComponentBindings API to unbind the component.

Note Older DDKs such as the Microsoft Windows 2000 DDK and the Windows XP Gold DDK contained the SNetCfg sample that demonstrated these APIs.

Change the network provider order
You can also change the network provider order so that a specific redirector is picked first. These redirectors include server message block (SMB), Web Distributed Authoring and Versioning (WebDAV), and Novell NetWare Client for Windows. The following are the registry subkeys that are related to the redirector.

You can change the network provider order in Control Panel. For more information, see the &quot;How to change the binding order of network adapters&quot; section. Or, you can change the network provider order by modifying the registry. To change the network provider order by modifying the registry, change the following registry key:

The following settings are the settings that you use to change the provider order:

Name: ProviderOrder

Type: REG_SZ

Value data: LanmanWorkstation,WebClient,RDPNP

The MoveBefore method and the MoveAfter method
You can write a tool in C++ to change the order of the network adapters and the bindings on Windows XP-based client computers. In the tool, use the following:
 * Use the INetCfgComponent API and the INetCfgComponentBindings API from the INetCfg interface.
 * Use the MoveBefore method and the MoveAfter method.

These two methods work as follows:
 * The MoveBefore method sets the order of two binding paths so that one path comes before the other path.
 * The MoveAfter method sets the order of the two binding paths the other way around.

Note These methods are documented in the &quot;Network configuration interfaces&quot; section of the Windows DDK. The &quot;Network configuration interfaces&quot; section of the Windows DDK discusses INetCfg interfaces.

The Bindview sample in the Windows DDK demonstrates how to use the INetCfgComponent API and the INetCfgComponentBindings API. The sample provides code that you can use to change the protocol binding order on a network adapter.

The following pseudo code sorts the bindings correctly. The INetCfg API is the Win32 call that the control program is using. For more information, see the Windows DDK.

Note The INetCfg API is located in the following location:

C:\Winnt\Syste32\Netcfgx.dll

To use the MoveBefore method, follow these steps:
 * 1) Enumerate the adapters.
 * 2) Find the Backup Network Connection interface.
 * 3) Use the MoveBefore method to assign the Backup Network Connection interface as the primary interface.

Note You can also pass a null value as the second parameter to assign the Backup Network Connection interface as the primary interface.
 * 1) Find the Primary Network Connection interface.
 * 2) Use the MoveBefore method to assign the Primary Network Connection interface as the primary interface. Now the Backup Network Connection interface is secondary.

Note You can also pass a null value as the second parameter to assign the Primary Network Connection interface as the primary interface.
 * 1) Set the Enable property to False in the INetCfgComponent class to disable the unused network interfaces. Or, use the netsh command.

Pseudo code
INetCfgComponent:Initialize INetCfg::QueryNetCfgClass( INetCfgClass ) INetCfgClass:: EnumComponents Call SetAsPrimary(&quot;Backup Network Connection&quot;) ' Set Backup network as primary Call SetAsPrimary(&quot;Primary Network Connection&quot;) ' Set Primary as primary, now Backup is secondary INetCfg::Uninitialize INetCfg::Release

Subroutine SetAsPrimary(Adapter) For each component ' For each enumerated component DisplayName = INetCfgComponent::GetDisplayName( INetCfgComponentBindings ) ' Get Adapter display name If DisplayName = Adapter Then InetCfgComponentBindings::MoveBefore(INetCfgComponent,Null) ' Move adapter binding to Primary Exit For Loop End If end For End Sub For example, if you want to move the binding in which the File and Printer Sharing (FPS) for Microsoft Networks network component is bound to TCP/IP to the top of the bindings for FPS, you have to enumerate the binding paths for FPS. Then, you have to find the binding path for TCP/IP. Call the INetCfgComponentBindings::MoveBefore method for FPS. Use the binding path for TCP/IP as the first parameter of the call, and use a null value in the second parameter.

