@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
网卡启用、禁用、重启批处理
最新推荐文章于 2024-09-02 19:34:28 发布
文章介绍了使用Windows批处理脚本实现网卡的启用、禁用和重启功能,包括获取网卡信息、处理用户输入和执行netsh命令以管理网络接口。


4765

被折叠的 条评论
为什么被折叠?



