发布网友 发布时间:2022-04-24 12:09
共2个回答
热心网友 时间:2022-07-10 10:02
@echo off & title 一键 禁/启 以太网 By 依梦琴瑶
::设置以太网(本地连接)名称
set ConName=本地连接
netsh interface show interface "%ConName%" | findstr "已禁用" >nul 2>nul && (
set State=enabled
set Msg=%ConName%已启用
) || (
set State=disabled
set Msg=%ConName%已禁用
)
netsh interface set interface "%ConName%" %State% && echo %Msg%
pause
此命令在已开启“用户帐户控制”的系统上需要右键管理员身份权限运行。
热心网友 时间:2022-07-10 10:02
@echo off
rem 如下示例是在Win10上测试的,在Win7等系统中,示例中“以太网”和“WLAN”要做相应替换。
rem 获取管理员权限
>NUL 2>&1 REG.exe query "HKU\S-1-5-19" || (
ECHO SET UAC = CreateObject^("Shell.Application"^) > "%TEMP%\Getadmin.vbs"
ECHO UAC.ShellExecute "%~f0", "%1", "", "runas", 1 >> "%TEMP%\Getadmin.vbs"
"%TEMP%\Getadmin.vbs"
DEL /f /q "%TEMP%\Getadmin.vbs" 2>NUL
Exit /b
)
rem 切换支持中文,注:以ANSI【GB2312 (Simplified)】编码保存后不再chcp切换。
rem chcp 65001
title 切换网络连接状态
rem 初始化网卡状态变量
set WiredConn=0
set WiredlessConn=0
rem 判断网卡状态
netsh interface show interface "以太网" | findstr "已禁用" >nul 2>nul && set WiredConn=0 || set WiredConn=1
netsh interface show interface "WLAN" | findstr "已禁用" >nul 2>nul && set WirelessConn=0 || set WirelessConn=1
rem 显示网卡状态
if %WiredConn% EQU 1 (echo 当前有线状态:启用) else (echo 当前有线状态:禁用)
echo.
if %WirelessConn% EQU 1 (echo 当前无线状态:启用) else (echo 当前无线状态:禁用)
rem 切换网卡连接状态
if %WiredConn% EQU %WirelessConn% ((netsh interface set interface "以太网" enabled >nul 2>nul && echo. & echo 成功启用有线) & (netsh interface set interface "WLAN" disabled > nul 2>nul && echo. & echo 成功禁用无线) & (goto endit))
if %WiredConn% EQU 1 (
if %WirelessConn% EQU 0 (
(netsh interface set interface "以太网" disabled >nul 2>nul && echo. & echo 成功禁用有线) & (netsh interface set interface "WLAN" enabled >nul 2>nul && echo. & echo 成功启用无线) & ((timeout /t 3 /nobreak >nul 2>nul) & (netsh wlan connect name=thl168-ICCT ssid=thl168-ICCT interface="WLAN" >nul 2>nul) & (echo 且已发送连接thl168-ICCT无线热点的请求。) & (goto endit))
)
) else (
(netsh interface set interface "以太网" enabled >nul 2>nul && echo. & echo 成功启用有线) & (netsh interface set interface "WLAN" disabled >nul 2>nul && echo. & echo 成功禁用无线) & (goto endit)
)
:endit
echo.
echo 3秒内自动关闭。
timeout /t 3 /nobreak
exit