dd: 修复镜像没有 wmic 时无法配置静态 IP

This commit is contained in:
bin456789
2025-10-05 23:35:36 +08:00
parent 1afc1a0022
commit 6708c77c63

View File

@ -19,7 +19,23 @@ netsh interface ipv6 set global randomizeidentifiers=disabled
rem 检查是否定义了 MAC 地址 rem 检查是否定义了 MAC 地址
if defined mac_addr ( 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 ( if defined id (
rem 配置静态 IPv4 地址和网关 rem 配置静态 IPv4 地址和网关
if defined ipv4_addr if defined ipv4_gateway ( if defined ipv4_addr if defined ipv4_gateway (