From 6708c77c6389aabb8267714ff5aed403bed5192d Mon Sep 17 00:00:00 2001 From: bin456789 Date: Sun, 5 Oct 2025 23:35:36 +0800 Subject: [PATCH] =?UTF-8?q?dd:=20=E4=BF=AE=E5=A4=8D=E9=95=9C=E5=83=8F?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=20wmic=20=E6=97=B6=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=9D=99=E6=80=81=20IP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- windows-set-netconf.bat | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/windows-set-netconf.bat b/windows-set-netconf.bat index c4d5fff..07fe54d 100644 --- a/windows-set-netconf.bat +++ b/windows-set-netconf.bat @@ -19,7 +19,23 @@ netsh interface ipv6 set global randomizeidentifiers=disabled rem 检查是否定义了 MAC 地址 if defined mac_addr ( - for /f %%a in ('wmic nic where "MACAddress='%mac_addr%'" get InterfaceIndex ^| findstr [0-9]') do set id=%%a + rem vista 没有自带 powershell + rem win11 24h2 安装后有 wmic,但是过一段时间会自动删除,因此有的 dd 镜像没有 wmic + if exist "%windir%\system32\wbem\wmic.exe" ( + for /f "tokens=2 delims==" %%a in ( + 'wmic nic where "MACAddress='%mac_addr%'" get InterfaceIndex /format:list ^| findstr /r "^InterfaceIndex=[0-9][0-9]*$"' + ) do set id=%%a + ) + if not defined id ( + for /f %%a in ('powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass ^ + -Command "(Get-WmiObject Win32_NetworkAdapter | Where-Object { $_.MACAddress -eq '%mac_addr%' }).InterfaceIndex" ^| findstr /r "^[0-9][0-9]*$"' + ) do set id=%%a + ) + if not defined id ( + for /f %%a in ('powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass ^ + -Command "(Get-CimInstance Win32_NetworkAdapter | Where-Object { $_.MACAddress -eq '%mac_addr%' }).InterfaceIndex" ^| findstr /r "^[0-9][0-9]*$"' + ) do set id=%%a + ) if defined id ( rem 配置静态 IPv4 地址和网关 if defined ipv4_addr if defined ipv4_gateway (