Recipe 12.2. Disabling a Connection


Problem

You want to disable a network connection for either a virtual interface or a network adapter.

Solution

Using a graphical user interface

  1. From the Control Panel open the Network Connections applet.

  2. Right-click the network connection you want to disable and select Disable.

Using a command-line interface

You would think that it would be straightforward to disable a connection from the command line, but unfortunately that is not the case. In fact, the netsh command supports disabling connections, but only non-LAN interfaces, which is very disappointing.

But all is not lost! There is an alternative if you really must have a way to disable connections from the command line. The devcon.exe tool is the command-line alternative to the Device Manager interface and comes with the Driver Development Kit (DDK). You can download it separately by viewing MS KB 311272 (http://support.microsoft.com/default.aspx?scid=311272).

Once you have it downloaded, run this command to get a list of all network devices:

> devcon listclass net

This displays the list of devices in two columns. The left column contains the hardware ID for each device, and the right column contains the description for the device.

After you've found the device you want to disable, run the following command:

> devcon disable =net <HardwareID>

For example:

> devcon disable =net PCI\VEN_14B9^&DEV_A504^&SUBSYS_500014B9^&REV_00

There are a couple of important things we need to point out. First, if the hardware ID contains any ampersands (&), you have to escape them using a caret (^). Otherwise, the CMD session will interpret everything after the first & as another command and devcon will attempt to match any hardware ID that matches the string up until the first &. This can be dangerous because it can cause you to disable devices you didn't intend to.

Second, if the hardware ID contains two backslashes, remove the second backslash and everything following it. For example, if the listall command returned this for a device we wanted to disable:

PCI\VEN_14B9&DEV_A504&SUBSYS_500014B9&REV_00\4&39A85202&0&10F0: Cisco Systems PC I Wireless LAN Adapter

then we would need to use this as the hardware ID (including the carets):

PCI\VEN_14B9^&DEV_A504^&SUBSYS_500014B9^&REV_00

Using VBScript

If you thought the command line way to disable connections was painful, we won't even begin to describe how it can be done via a script. There is a way, but it essentially involves simulating the steps in the graphical solution. Because the script is a major hack and not very reliable, we won't include it here. We will make it available on the book's website (http://www.rallenhome.com/) in case you are still interested.

A somewhat viable mechanism for using VBScript is to shell out to the devcon.exe tool to accomplish your objectives. Don't forget the escaping!

Discussion

Some workstations come with two network adapters installed to avoid a single point of failure with the network connection. Generally, you'll only want one connection to be active and use the other as a back up. There are a couple of ways to do this. One is to simply disable one of the connections and manually enable it if the primary fails. Since you probably won't have network connectivity after the primary adapter fails, you'll need another way to access the server, such as an out-of-band console connection of some type.

Another way to do this is to use a feature that many hardware vendors support now called teaming . With teaming, both adapters are used to form a virtual adapter. If the primary adapter becomes unavailable, the backup takes over automatically. (See your hardware vendor for more details.) The problem with teaming is that, depending on the implementation, it can be unreliable and ultimately cause more configuration headache than it is worth. We recommend testing teaming configurations thoroughly before implementing them in production.

See Also

MS KB 262265, "Error Message When You Use Netsh.exe to Enable or Disable a Network Adapter"



Windows XP Cookbook
Windows XP Cookbook (Cookbooks)
ISBN: 0596007256
EAN: 2147483647
Year: 2006
Pages: 408

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net