简体   繁体   English

在Windows 10 CMD脚本中获取SSID

[英]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.

相关问题 如何以编程方式连接到 Windows 10 中的隐藏 SSID? - How do I connect to a hidden SSID in Windows 10 programmatically? Windows CMD 批处理脚本中的文件名时间戳被截断 - Filename timestamp in Windows CMD batch script getting truncated Javac在cmd Windows 10中不起作用 - Javac not working in cmd windows 10 Heroku无法在Windows 10的CMD上运行 - Heroku not working on CMD on windows 10 如何仅通过在 Windows 10 cmd 行上键入脚本名称来运行 python 程序? - How do i run a python program just by typing the script name on windows 10 cmd line? Windows 10 任务计划程序:执行 bash 脚本而不显示 cmd - Windows 10 Task Scheduler: Execute bash script without showing up cmd 如何在Windows 10中的命令提示符(cmd)中从带有子进程模块的python脚本编写命令 - how to write command in command prompt (cmd) in windows 10 from python script with subprocess module Windows 10 - 清除 CMD 批处理脚本中的事件日志,所有输出都在同一行上运行? - Windows 10 - Clearing Event Logs in CMD batch script with all output running on same line? Python 脚本不返回值尽管程序以交互方式正确运行(windows10 cmd) - Python script doesn't return values altough program runs correctly interactively(windows10 cmd) 将 WiFi 切换 Linux shell 脚本翻译到 Windows10 CMD 或 Z3D265B4E13EEB10DDF17881FA0 - Translating WiFi switching Linux shell script to Windows10 CMD or PowerShell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM