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?
37 Answers
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.
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 1The 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 1Thanks 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 1VERY 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.
1echo 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 1Props 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.