当我登录 Windows 7 时,我需要等待 10 秒,然后禁用本地连接(以太网适配器),然后重新启用它。
我查看了建议的答案:在 bat 文件中启用/禁用无线接口但这似乎无关紧要,因为它只是切换当前状态。
据我所知,我需要包括:
netsh interface set interface "Local Area Connection" DISABLED
netsh interface set interface "Local Area Connection" ENABLED
但我不确定等待时间是多少,也不确定如何在 Windows 成功登录后启动它。
这里最好的方法是什么?
答案1
创建带有触发器的 Windows 计划任务(taskschd.msc
或Control Panel\System and Security\Administrative Tools\Task Scheduler
):开始任务At log on
并在高级设置中延迟任务30 seconds
。然后添加操作Start a program
并选择您的.bat
脚本。
答案2
我希望这有帮助
@echo on
timeout /t 10
netsh interface set interface "Local Area Connection" DISABLED
timeout /t 10
netsh interface set interface "Local Area Connection" ENABLED
答案3
逻辑是:ping 公共 IP(google dns 8.8.8.8),如果 ping 失败,则转到:RESTART 并重新启动名为“LAN”的网络适配器,之后再次从头开始循环(如果 ping 正常,则不执行任何操作并循环 ping 以检查适配器是否已连接到互联网)
@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
答案4
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