The simple way to disable/enable LAN from command prompt, with a batch file, using devcon.exe

  • Thread starter Thread starter setup21
  • Start date Start date
Unfortunately, this tip will only work for folks who have the same network
adapter that you do.

--
Richard G. Harper [MVP Shell/User] (e-mail address removed)
* PLEASE post all messages and replies in the newsgroups
* for the benefit of all. Private mail is usually not replied to.
* My website, such as it is ... http://rgharper.mvps.org/
* HELP us help YOU ... http://www.dts-l.org/goodpost.htm
 
The problem can be overcome by giving the command
some intelligence, namely by specifying the network adapter's
name, as it appears in the Control Panel (verbatim!) in this
batch file:

Device.bat
=======
@echo off
goto Start
---------------------------------------------------
Use this batch file to enable or disable a device
from the Command Prompt.
16.4.2006 FNL
---------------------------------------------------
:Start
setlocal enabledelayedexpansion
set Adapter=Broadcom NetXtreme Fast Ethernet

if /i "%1"=="enable" goto go
if /i "%1"=="disable" goto go
echo Syntax: Device enable / disable
goto :eof

:go
set HWID=x
set count=0
set found=no

devcon hwids "PCI\*" > device.txt
for /F "tokens=*" %%* in (device.txt) do (
set /a count=!count! + 1
if /i "%%*"=="Name: %Adapter%" set found=yes& set count=1
if !found!==yes if !count!==3 set HWID=%%*
)
if %found%==yes (
echo HWID=!HWID!
devcon %1 "!HWID!"
) else (
echo Device "%Adapter%" not found.
)
endlocal
del device.txt

Richard G. Harper said:
Unfortunately, this tip will only work for folks who have the same network
adapter that you do.

--
Richard G. Harper [MVP Shell/User] (e-mail address removed)
* PLEASE post all messages and replies in the newsgroups
* for the benefit of all. Private mail is usually not replied to.
* My website, such as it is ... http://rgharper.mvps.org/
* HELP us help YOU ... http://www.dts-l.org/goodpost.htm


1.Download Devcon.exe from Microsoft:

http://download.microsoft.com/download/1/1/f/11f7dd10-272d-4cd2-896f-9ce67f3e0240/devcon.exe

2. Create a batch file with the following single line:

devcon disable "pci\ven_8086&dev_27dc"

(don't forget quotation marks).

That's all.

Enable with:
devcon enable "pci\ven_8086&dev_27dc"
 
You could give it even more intelligence by using WMI calls to enumerate the
various network adapters present and tossing out the known entries that
aren't physical connections - but by that time I can right-click the network
status icon I put down by the clock and disable and re-enable it. :-)

--
Richard G. Harper [MVP Shell/User] (e-mail address removed)
* PLEASE post all messages and replies in the newsgroups
* for the benefit of all. Private mail is usually not replied to.
* My website, such as it is ... http://rgharper.mvps.org/
* HELP us help YOU ... http://www.dts-l.org/goodpost.htm
 
download devcon form Microsoft

1. Find the registry key for your adapter [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\
2. Find the ID of your network adapter
example: devcon hwids PCI\VEN*

then find at this simple script your answer
bowdown.gif


@echo off
set ip=182.31.24.21
set mac=4C0010524026
set interface=Local Area Network
set mask=255.255.255.0
set gateway=182.31.24.1
set dns1=212.221.112.2
rem ======================
set metric=0
set mac_reg=[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0002]
devcon disable PCI\VEN_10EC
echo Windows Registry Editor Version 5.00 > tmp%interface%.reg
echo %mac_reg% >> tmp%interface%.reg
echo "networkaddress"="%mac%" >> tmp%interface%.reg
regedit /s tmp%interface%.reg
del tmp%interface%.reg
netsh interface ip set address name=%interface% static %ip% %mask% %gateway% %metric%
netsh interface ip set dns name=%interface% static %dns1%
devcon enable PCI\VEN_10EC
 
Back
Top