19

When I log into Windows 7 I need to wait 10 seconds and then disable the Local Area Connection (ethernet adaptor) and then reenable it.

I have looked through the suggested answer: Enable/disable wireless interface in a bat file but that seems irrelevant as it just toggles the current state.

From what I can tell I need to include:

netsh interface set interface "Local Area Connection" DISABLED
netsh interface set interface "Local Area Connection" ENABLED

but I'm unsure of the wait time or how I can have this start after Windows has successfully logged in.

What's the best approach here?

3
  • 2
    Why do you need to wait 10 seconds, disable the LAN and then re-enable it? Dec 18, 2012 at 1:51
  • 1
    Tell us the underlying problem, it may be more sensible to solve that than to mess with interface.
    – Paul
    Dec 18, 2012 at 2:42
  • I use 2 x TL-PA211 EOP adaptors (www.tp-link.com/en/products/details/?model=TL-PA211) to connect to my home modem/router. The issue is that whenever I boot up my machine, my ethernet adaptor does not automatically connect, instead I see the following: - i.imgur.com/weFHV.jpg – it tells me that I am connected to my usual home network plus an Unidentified network. I then have to disable my ethernet adaptor and reenable it and then it connects to my usual home network - every time I turn the computer on. I am using the TL-PA2111 pairing application and my Ethernet drivers are up to date.
    – rlsaj
    Dec 18, 2012 at 3:50

7 Answers 7

11

Create a Windows Scheduled Task (taskschd.msc or Control Panel\System and Security\Administrative Tools\Task Scheduler) with a Trigger: begin the task At log on and in the Advanced settings delay task for 30 seconds. Then add an Action to Start a program and select your .bat script.

0
32

I hope this helps

@echo on
timeout /t 10
netsh interface set interface "Local Area Connection" DISABLED
timeout /t 10
netsh interface set interface "Local Area Connection" ENABLED
1
  • Upvoted because it's just, what I was looking for, I needed a 2 sec delay between the on and off and no initial, for when sometimes my card refuses to get a connection on startup, so I have a handy bat file on the desktop
    – Limiter
    Aug 1, 2014 at 16:24
3

The logic is: ping public ip (google dns 8.8.8.8), if the ping fails, then goto :RESTART and restart network adapter with name "LAN", after this loop again from the start (if ping is OK, then do nothing and ping in loop to check if adapter is connected to internet)

   @echo off 

    :LOOP
    ping 8.8.8.8
    IF ERRORLEVEL 1 goto RESTART
    IF ERRORLEVEL 0 goto LOOP
    :RESTART
    netsh interface set interface "LAN" disabled
    ping -n 3 127.0.0.1
    netsh interface set interface "LAN" enabled
    ping -n 15 127.0.0.1
    goto LOOP
1
  • 1
    Like the logic you put in for looping!
    – Colin
    Aug 30, 2015 at 18:08
1

VERY USEFUL info here but one piece that is missing in the answers is what to enter in the "Local Area Network". I came across this answer:

"The first step is to find the name of your wireless connection. [Right click the WiFi symbol] > Open Network and Sharing Center > Change adapter settings. It is the top line of the connection info. Mine simply said Wi-Fi, but it could be Wireless Network Connection, etc."

BTW, if it is the LAN network card, I believe you just need to look for the name for that device.

That was key to make it work for me.

1
1
echo off
cls 
:start
echo Choice 1
echo Choice 2
set /p choice=Yes or No?
if '%Choice%'=='1' goto :choice1
if '%Choice%'=='2' goto :choice2
echo "%Choice%" is not a valid option. Please try again. 
echo
goto start
:choice1
netsh interface set interface "Ethernet" admin=Enable
goto end 
:end
pause
exit  
:choice2
netsh interface set interface "Ethernet" admin=disable
goto end 
:end
pause
exit 
1
  • I think your answer needs some explanations also for better understanding and will reflect your observations also all around the issue. Jan 17, 2018 at 6:48
0

Props to the kind soul who helped setup the loop. I changed it slightly as it refused to work on SP3. Below is my updated disable/enable, based on the code provided above!

@echo off

:LOOP
ping 8.8.8.8
IF ERRORLEVEL 1 goto RESTART
IF ERRORLEVEL 0 goto LOOP
:RESTART
devcon disable "PCI\VEN_1317&*"
ping -n 3 127.0.0.1
devcon enable "PCI\VEN_1317&*"
ping -n 15 127.0.0.1
goto LOOP

While this does require devcon to work, this is a readily available tool from Microsoft and does a much cleaner job enabling or disabling a troublesome adapter.

http://thilina.piyasundara.org/2011/06/enabledisable-lan-interface-by-command.html shows how to do this well.

0

Thanks guys,

I am using this command to disable and enable the problematic WiFi network adapter;

> @echo on
> timeout /t 10
> netsh interface set interface "Wi-Fi" DISABLED
> timeout /t 2
> netsh interface set interface "Wi-Fi" ENABLED
1
  • Welcome to Super User! This duplicates another answer and adds no new content. Please don't post an answer unless you actually have something new to contribute.
    – DavidPostill
    Aug 8, 2016 at 7:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .