网卡启用、禁用、重启批处理

文章介绍了使用Windows批处理脚本实现网卡的启用、禁用和重启功能,包括获取网卡信息、处理用户输入和执行netsh命令以管理网络接口。
@echo off
:init
setlocal DisableDelayedExpansion
set "batchPath=%~0"
for %%k in (%0) do set batchName=%%~nk
set "vbsGetPrivileges=%temp%\MYSQL_INIT_getPriv_%batchName%.vbs"
setlocal EnableDelayedExpansion
:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
:getPrivileges
if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
ECHO args = "ELEV " >> "%vbsGetPrivileges%"
ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
ECHO args = args ^& strArg ^& " "  >> "%vbsGetPrivileges%"
ECHO Next >> "%vbsGetPrivileges%"
ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
"%SystemRoot%\System32\WScript.exe" "%vbsGetPrivileges%" %*
exit /B
:gotPrivileges
setlocal & pushd .
cd /d %~dp0
if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul  &  shift /1)


@echo off
:startMe
cls
setlocal enabledelayedexpansion

title 网卡启用,禁用,重启工具
color 1f
cls
echo.
echo ==================================================================================================
echo 			当网卡出现问题,可以禁用,启用或重启网卡
echo.                          
echo                            		--—作者:郴州科泰-陈老师
echo.  
echo ==================================================================================================
REM 读取当前可以使用的网卡信息



set num=1
set no=1
REM set DID=1
for /f "tokens=2 delims==" %%i in ('wmic nic where "not NetConnectionID is null" get NetConnectionID^,DeviceID /value') do (
	set /a mo=!num!"%%"2
	REM if "!mo!" == "1" (
		REM set DID=%%i 
	REM )
	if "!mo!" == "0" (
		set NetID=%%i  
		set "Obj[!no!].NetID=%%i"
		echo     !no! 、 网卡名称:!NetID! 
		set /a no+=1
	)
	set /a num+=1
	
)
set /a no-=1
echo ==================================================================================================
echo. 

set /p choice=请输入序号:

set choiceNetID=!Obj[%choice%].NetID!
echo 选择的网卡是:%choiceNetID%

echo.
echo ========================================
echo  1、启用
echo  2、禁用
echo  3、重启
set /p choice_type=请选择操作:
echo ========================================

if "%choice_type%" == "1" (
	echo 正在启用网卡:!choiceNetID!
	netsh interface set interface name="%choiceNetID%" admin=ENABLED
)

if "%choice_type%" == "2" (
	echo 正在禁用网卡:!choiceNetID!
	netsh interface set interface name="%choiceNetID%" admin=DISABLED
)

if "%choice_type%" == "3" (
	echo 正在重启网卡:!choiceNetID!
	netsh interface set interface name="%choiceNetID%" admin=DISABLED
	netsh interface set interface name="%choiceNetID%" admin=ENABLED
)
pause
goto startMe

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值