码迷,mamicode.com
首页 > Windows程序 > 详细

启用/禁用以太网的批处理,用于一个网卡切换本地网络和wifi使用(Win10)

时间:2018-09-03 10:35:23      阅读:1529      评论:0      收藏:0      [点我收藏+]

标签:state   pushd   roo   int   ndt   禁用   stat   bsp   win   

注意下面时英文版上默认网络使用,同时接入了网线和wifi时,本地网络优先wifi。

所以禁用本地网络就会自动连接到wifi,启用本地网络,就会禁用wifi。

批处理支持 -slice 参数,代码如下:

SwitchEthernet.bat

 1 @echo off
 2 pushd "%~dp0"
 3 set name="Ethernet"
 4 set findtext="Administrative state: Enabled"
 5 
 6 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\SYSTEM" >nul 2>nul
 7 if %errorlevel%==0 goto :START
 8 
 9 echo ** Please use administrator account to run. **
10 goto :END
11 
12 :START
13 set input=
14 set slice=0
15 if "%1"=="-slice" set slice=1
16 netsh interface show interface name=%name%
17 netsh interface show interface name=%name% | find %findtext% > nul
18 if ERRORLEVEL 1 goto :OP_ENABLED
19 :OP_DISABLED
20 echo.
21 if %slice% equ 1 goto :op_d_skip
22 set /p input=Input ‘Y‘ to DISABLE interface %name% [y/N]:
23 goto :op_d_run
24 :op_d_skip
25 echo Input ‘Y‘ to DISABLE interface %name% [y/N]:y
26 set input=Y
27 :op_d_run
28 if /i "%input%"=="Y" netsh interface set interface name=%name% admin=DISABLED
29 goto :END
30 :OP_ENABLED
31 echo.
32 if %slice% equ 1 goto :op_e_skip
33 set /p input=Input ‘Y‘ to ENABLED interface %name% [y/N]:
34 goto :op_e_run
35 :op_e_skip
36 echo Input ‘Y‘ to ENABLED interface %name% [y/N]:y
37 set input=Y
38 :op_e_run
39 if /i "%input%"=="Y" netsh interface set interface name=%name% admin=ENABLED
40 goto :END
41 :END
42 echo.
43 echo Current Status:
44 netsh interface show interface
45 if %slice% equ 1 goto :skip_any_key
46 echo Press any key to exit...
47 pause > nul
48 goto :end1
49 :skip_any_key
50 echo Will exit in 5 seconds...
51 ping 127.1 -n 6 > nul
52 :end1
53 popd

 

启用/禁用以太网的批处理,用于一个网卡切换本地网络和wifi使用(Win10)

标签:state   pushd   roo   int   ndt   禁用   stat   bsp   win   

原文地址:https://www.cnblogs.com/Bob-wei/p/9577140.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!