Windows cmd命令提示符重启网卡(网络适配器)

Windows cmd命令提示符重启网卡(网络适配器)

查询计算机上所有的网卡(包括虚拟网卡)

1
netsh interface show interface

操作网卡的指令

关闭网卡:

1
netsh interface set interface "要操作的网卡名称" disable

开启网卡:

1
netsh interface set interface "要操作的网卡名称" enable

以无线网卡WLAN为例,重启网卡(在管理员权限cmd窗口运行)

1
2
netsh interface set interface "WLAN" disable
netsh interface set interface "WLAN" enable

实例cmd脚本

脚本名:WLAN_Check.bat

脚本功能:当wifi断网后自动重启WLAN(网络适配器)

操作方式:将该脚本添加到任务计划程序,配置启动时运行,设置无限期每隔5分钟运行一次。配置后先手动运行一下后就不用再管了。

脚本内容:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
@echo off
echo 开始网络连接监控...

:Check
echo 正在检查网络连接...
ping -n 3 www.baidu.com > nul

if %ERRORLEVEL% EQU 0 (
    echo 网络连接正常,等待60秒后再次检查...
    timeout /t 60 /nobreak > nul
    goto Check
) else (
    echo 网络连接失败,错误代码: %ERRORLEVEL%
    echo 正在重启WLAN适配器...
    goto RestartWLAN
)

:RestartWLAN
echo 禁用WLAN...
netsh interface set interface "WLAN" disable

echo 等待5秒...
timeout /t 5 /nobreak > nul

echo 启用WLAN...
netsh interface set interface "WLAN" enable

echo 等待10秒让网络重新连接...
timeout /t 10 /nobreak > nul

echo 重新检查网络连接...
goto Check
Licensed under CC BY-NC-SA 4.0
最后更新于 Sep 19, 2025 13:40 +0800
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计