win7 有线、无线网络自动切换

查看 116|回复 9
作者:sxp3468   
找了个有线、无线网络自动切换批处理,发现能在win10下正常,但在win7下不能实现切换,请求老师帮忙怎样才实现在WIN7下可用?
..................................................................................
批处理如下:
@ echo off  
echo 正在启用超级管理员权限...   
%1 %2  
ver|find "5.">nul&&goto :st  
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :st","","runas",1)(window.close)&goto :eof  
  
:st  
copy "%~0" "%windir%\system32\"  
echo 启用超级管理员权限成功   
@echo off
netsh interface show interface "以太网" | find "管理状态: 已启用" >nul && (
  echo connected - disconnecting...
  netsh interface set interface "以太网" disabled
  netsh interface set interface "WLAN" enable
  echo 当前为WLAN
) || (
  echo disconnected - connecting
  netsh interface set interface "以太网" enabled
  netsh interface set interface "WLAN" disable
  echo 当前为以太网
)
pause
exit

以太网, 无线网络

flysnow99   

WIN10 叫“以太网”
WIN7 叫“本地连接”
像孩子y1样   

WIN7系统下的有线和无线名字和WIN10不太一样
WIN7有线网一般叫:本地连接
无线网一般叫:无线网络连接
所以你可以把上面的“以太网”和“WLAN”改下名字试试   
syd1990   

[Asm] 纯文本查看 复制代码@echo off
setlocal enabledelayedexpansion
set "connectionType="
for /f "tokens=2 delims=: " %%a in ('ipconfig ^| find "Ethernet adapter"') do (
    set "connectionType=%%a"
)
if "!connectionType!" == "有线网络" (
    netsh interface set interface "有线网络" disabled
    netsh interface set interface "无线网络" enabled
    echo "已启用无线网络"
) else (
    netsh interface set interface "无线网络" disabled
    netsh interface set interface "有线网络" enabled
    echo "已启用有线网络"
)
像孩子y1样   


像孩子y1样 发表于 2023-3-21 09:35
WIN7系统下的有线和无线名字和WIN10不太一样
WIN7有线网一般叫:本地连接
无线网一般叫:无线网络连接

如果改了还是显示不对的话。
你在CMD里面输入 netsh interface show interface
查看无线和有线网对应显示的接口名称,然后改成对应的就行了。
sxp3468
OP
  

谢谢各位指点
sxp3468
OP
  


syd1990 发表于 2023-3-21 09:36
[mw_shl_code=asm,true]@echo off
setlocal enabledelayedexpansion
set "connectionType="

不知道什么原因,运行后,没能切换
Wzs313   

这相当有用!
mokson   

楼主,你大意了。
sxp3468
OP
  


mokson 发表于 2023-3-21 11:08
楼主,你大意了。

对哦   低级
您需要登录后才可以回帖 登录 | 立即注册

返回顶部