@echo off && setlocal ENABLEDELAYEDEXPANSION
title 重新启动 以太网适配器
color 0a
echo.
set m=0
set p=0
if exist net_dev.txt del /q net_dev.txt
for /f "tokens=1,2*" %%c in ('ipconfig /all') do (
set /a m=!m!+1
if %%c*==以太网适配器* (
set /a n=!m!+2
set l=%%d
set l=!l:~0,-1!)
if %%c_%%d*==Ethernet_adapter* (
set /a n=!m!+3
set l=%%e
set l=!l:~0,-3!
)
if !m!==!n! (
set /a p=!p!+1
for /f "tokens=1* delims=:" %%x in ("%%c%%d%%e") do (echo !p!:!l!:%%y>>net_dev.txt)
)
)
for /f %%c in ("m n l p") do set %%c=
if exist net_dev.txt (
for /f "delims=: tokens=1*" %%c in ('devcon find pci\*') do (
for /f "tokens=1,2* delims=:" %%x in (net_dev.txt) do (
if "%%d"=="%%z" (
for /f "delims=& tokens=2" %%i in ("%%c") do (
echo 正在重新启动 %%x.%%y:%%z
devcon disable *%%i* >nul
devcon enable *%%i* >nul
)
)
)
)
del /q net_dev.txt
)
echo.
echo 指令运行完毕! 按任意键退出.... &&pause>nul