How to Configure the Network Connection Order automatically in Windows Vista?

How to Configure the Network Connection Order automatically in Windows Vista?

Introduction



 This topic is a how to.
Please keep it as clear and simple as possible. Avoid speculative discussions as well as a deep dive into underlying mechanisms or related technologies.


Basic Overview


In many scenarios, laptops may have different network card (LAN, wireless, 3G, etc...).
Depending of the location will need only one of them to connect to the network or internet. Here is how we can define which one will try to connect first.

Explanations

You cannot change the binding order with a group policy, registry change or netsh command. Keep in mind that network adapters are plug-and-play devices that the Windows Vista will automatically detect and use.

The best two solutions are

  • Using a 3rd party sofftware like

            http://www.mobilenetswitch.com
            http://www.netswitcher.com/

Here is a cool sample from the article:

(I kept the original format)

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 "Network configuration interfaces" section of the Windows DDK. The "Network configuration interfaces" 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.
  4. Find the Primary Network Connection interface.
  5. 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.
  6. 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("Backup Network Connection") ' Set Backup network as primary

Call SetAsPrimary("Primary Network Connection") ' 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.

Complementary links:

http://gallery.technet.microsoft.com/ScriptCenter/en-us/

 

Leave a Comment
  • Please add 7 and 3 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
Page 1 of 1 (3 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
Page 1 of 1 (3 items)