Windows 批处理文件变量在循环中包含空格/特殊字符

问题描述 投票:0回答:0

在 Windows 10 上的批处理文件中使用它:

@echo off
setlocal enabledelayedexpansion

set "profile=NetworkProfileName"
set result=

for /F "tokens=2 delims=: usebackq" %%F IN (`netsh wlan show profile %profile% key^=clear ^| findstr "Key Content"`) do (
  set "result=%%F"
)

echo %profile% has password:!result!
endlocal

我得到预期的结果:

NetworkProfileName has password: SuperSecretPassword

当我使用网络配置文件名称包含特殊字符和空格像这样

set "profile=Wu-Tang LAN"

循环中找不到配置文件,密码变量一直为空:

Wu-Tang LAN has password: 

如果我直接在

cmd
中运行这个命令:

netsh wlan show profile "Wu-Tang LAN" key=clear | findstr "Key Content"

我得到了预期的输出:

Key Content : OtherSecretPassword

即使是 ChatGPT 4 也无法让我越线!秘诀是什么?

batch-file cmd netsh vlan
© www.soinside.com 2019 - 2024. All rights reserved.