[英]Getting SSID in Windows 10 CMD script
I need to pass the SSID name to my simple script with the main line as follows 我需要将SSID名称传递给带有主行的简单脚本,如下所示
netsh wlan set profileparameter name="SSID" cost=variable
So I know I can get the SSID from executing 所以我知道我可以从执行中获取SSID
Netsh WLAN show profiles
and looking at the line " Current user profile " find needed value. 并查看“ 当前用户个人资料 ”行,找到所需的值。 But without grep and sed how can I use the value from command output? 但是如果没有grep和sed,如何使用命令输出中的值?
PS The idea is to use native Windows tools, not CigWin or UNIX services ie not to install any additional software if it is possible. PS的想法是使用本机Windows工具,而不是CigWin或UNIX服务,即,如果可能的话,不安装任何其他软件。
Use a for /f
loop to get the output of a command. 使用for /f
循环获取命令的输出。 You could use proper tokens and delims to extract the part of the line you want, but the syntax is a bit weird to use quotes as delimter: 您可以使用适当的标记和delims提取所需行的一部分,但是使用引号作为delimter的语法有点奇怪:
for /f tokens^=2delims^=^" %%a in ('Netsh WLAN show profile "profilename"^|find "SSID-Name"') do set "SSIDa=%%a"
echo a: %SSIDa%
Another possibilty is to use the colon as delimiter. 另一个可能性是使用冒号作为定界符。 But then you have to remove the extra space and the quotes: 但是然后您必须删除多余的空间和引号:
for /f "tokens=2 delims=:" %%a in ('Netsh WLAN show profile "profilename"^|find "SSID-Name"') do set "SSIDb=%%~a"
echo b: %SSIDb:~2,-1%
You can also use a second for
to get the last token of the line (which happens to be the name you want): 您还可以使用第二个for
获得行(这恰好是你想要的名称)的最后一个记号:
for /f "delims=" %%a in ('Netsh WLAN show profile "profilename"^|find "SSID-Name"') do for %%b in (%%a) do set "SSIDc=%%~b"
echo c: %SSIDc%
A fourth possibilty is to use tokens=3
(with standard delimiters), but that's a bad (insecure) choice because the output (number of tokens) might change with localization (on the other hand, also your search string SSID-Name
is localization dependent). 第四个可能性是使用tokens=3
(使用标准定界符),但这是一个错误的选择(不安全),因为输出(令牌的数量)可能会随本地化而变化(另一方面,搜索字符串SSID-Name
也是本地化依赖)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.