Saturday, April 11, 2009

disable/enable network from command line for script

tried on windows xp
get devcon.exe (just search for it) and copy to system32 folder (or in ur path)

get the hardware id for ur network adaptor by using command
devcon findall * > id.txt
open the text file to see the network id
PCI\VEN_8086&DEV_10BD&SUBSYS_82681043&REV_02\3&11583659&0&C8: Intel(R) 82566DM-2 Gigabit Network Connection

copy the line just before &REV...
and run this command
devcon disable "PCI\VEN_8086&DEV_10BD&SUBSYS_82681043"

note the colon
to enable, just replace it with 'enable'
------------

more from internet

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.)
----------------

1 comment:

awhan said...

useful tool thanks :)

http://support.microsoft.co/kb/311272