使用 BAT 脚本更改网卡名称需要管理员权限,可以使用以下代码:

@echo off
setlocal enabledelayedexpansion

echo Searching for network adapters...
set found=0
for /f "tokens=2 delims=: " %%a in ('ipconfig /all ^| find "Adapter"') do (
    set /a found=!found!+1
    set adapter[!found!]=%%a
    echo !found!. !adapter[!found!]!
)

if !found! equ 0 (
    echo No network adapters found.
    pause
    exit /b 1
)

set /p choice=Enter the number of the adapter to rename: 

if !choice! gtr !found! (
    echo Invalid choice.
    pause
    exit /b 1
)

set /p newname=Enter the new name for the adapter: 

echo Renaming adapter !adapter[%choice%]! to !newname!...
netsh interface set interface name='!adapter[%choice%]!' newname='!newname!'

echo Done.
pause

这段代码会列出所有网络适配器的名称,然后让用户选择要更改的适配器,并输入新的名称。最后使用 netsh 命令来更改适配器名称。

如果运行时出现“No network adapter found.”的错误提示,可能是因为没有找到任何网络适配器。可以尝试检查一下计算机是否已经连接到网络,并确保网络适配器已经正确安装。

如何使用 BAT 脚本更改网卡名称并自动检测

原文地址: https://www.cveoy.top/t/topic/jC0c 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录