Hi, compuplus-ga:
Enabling or disabling a "network connection" by right-clicking has to
do with a specific network adapter (real or virtual). I will
therefore pursue actions on a single adapter, as opposed to enabling
or disabling your entire network.
The question of doing this programmatically has been explored here:
[Does anyone know of a way to Disable/Enable a NIC through a script?]
http://dbforums.com/arch/195/2002/7/429687
The approach adopted by the original poster (there) was this, a
scripting solution written by Michael Harris, a Microsoft "MVP":
[Re: How to disable-Enable Local area Connection via script]
http://groups.google.com/groups?threadm=OcFYOQD1BHA.2848%40tkmsftngp05
Apparently the script, in order to work reliably under Win2K, is
slightly more complex than it would need to be to work only for WinXP.
If such a scripting approach is not within the bounds of your "using
visual basic or the command prompt", a simpler alternative might be
this:
[FILE: DevCon Command Line Utility Alternative to Device Manager]
http://support.microsoft.com/support/kb/articles/q311/2/72.asp
which let's you download a (non-redistributable) command line utility
devcon.exe to enable or disable network adapters (and other devices;
actually to do pretty much everything you can in Device Manager,
including updating drivers) from the command line.
If you download the file devcon.exe and run it, it self-unzips into
your (current user's) "Local Settings\Temp" directory, or rather into
two subdirectories:
"Local Settings\Temp\i386"
and:
"Local Settings\Temp\ia64"
The latter holds the 64-bit version, which probably we need not
discuss further, and the Temp directory gets a file named EULA.txt for
obvious reasons.
The 32-bit utility devcon.exe in i386 can be run as:
devcon help
or:
devcon help <specific option>
to obtain help with commands and a few examples. See Microsoft's Web
page above for additional examples and information.
In particular after downloading and unpacking, I ran the command:
devcon listclass net
which showed all network adapters (real and virtual) on my WinXP
laptop. The first two are the actual hardware adapters, a built in
Ethernet adapter (Intel) and a wireless PCMCIA Ethernet adapter
(Linksys). The results are presented as a "hardware" device ID
followed by a description:
PCI\VEN_8086&DEV_2449&SUBSYS_30138086&REV_03\4&1351887D&0&40F0:
Intel(R) PRO/100 VE Network Connection
PCMCIA\INSTANT_WIRELESS_-_NETWORK_PC_CARD-317F\1 :
Instant Wireless - Network PC CARD
All the remaining "virtual" adapters have id's that begin with
"ROOT...". Therefore I experimented with the command to disable just
the built in Ethernet adapter:
devcon disable =net PCI\VEN*
which illustrates the use of a wildcard character in the "hardware"
ID.
The output from this command was:
PCI\VEN_8086&DEV_2449&SUBSYS_30138086&REV_03\4&1351887D&0&40F0:
Disabled
1 device(s) disabled.
Sure enough, when I went to view the network connections, this adapter
was disabled. I then did the obvious "undo" command:
devcon enable =net PCI\VEN*
which produced the output:
PCI\VEN_8086&DEV_2449&SUBSYS_30138086&REV_03\4&1351887D&0&40F0:
Enabled
1 device(s) enabled.
Even before going back to view the network connections again, I knew
the command had worked because a balloon popped up over the "Local
Area Connection" on my taskbar to inform that "A network cable is
unplugged." (Quite true, since I'm connected by the wireless adapter
to send this message.)
In short the devcon.exe utility does what you want (and much more;
what we call in mathematics the "big hammer" approach) as a "black
box". If you want to get down into the inner workings of the OS, then
the scripting approach may be attractive.
regards, mathtalk-ga |