本帖最后由 pcl_test 于 2017-4-2 17:09 编辑
无效则使用第三方devcon
http://www.bathome.net/s/tool/index.html?key=devcon- @echo off
- set "网络连接名称=本地连接"
- ::启用为1,禁用为0
- set "模式=0"
- ver|findstr "\<5\.[12]">nul||goto :2
- :1
- (
- echo;Set objshell = CreateObject("Shell.Application"^)
- echo;Set objnet = objshell.NameSpace("::{7007ACC7-3202-11D1-AAD2-00805FC1270E}"^).Items(^)
- echo;For i = 0 To objnet.Count - 1
- echo; If objnet.Item(i^).Name = "%网络连接名称%" Then
- echo; objnet.Item(i^).Verbs(^).Item(0^).DoIt
- echo; End If
- echo;Next
- echo;CreateObject("WScript.Shell"^).popup "Done",2,"提示",64
- )>"%tmp%\tmp.vbs"
- wscript -e:vbscript "%tmp%\tmp.vbs"
- goto :end
-
- :2
- for /f "delims=" %%a in ('wmic nic where "NetConnectionID='%网络连接名称%'" get DeviceID /value 2^>nul^|find "="') do set %%a
- if "%模式%" equ "0" (
- netsh interface set interface "%网络连接名称%" disabled >nul
- wmic path win32_networkadapter where DeviceID=%DeviceID% call disable
- ) else (
- netsh interface set interface "%网络连接名称%" enabled >nul
- wmic path win32_networkadapter where DeviceID=%DeviceID% call enable
- )
- :end
- pause
复制代码
|