I'm trying to get the wifi password with a batch file but one command is not being read correctly (my interpretation).
Netsh WLAN show profile name= %WifiName% key='clear'
turns into
Netsh WLAN show profile name= %WifiName% key 'clear'
when run in
for /f "tokens=*" %%i in ('Netsh WLAN show profile name= %WifiName% key="clear"') do ^
echo "%%i"
If you need more information ill give it but I'm too stupid to think of any right now.
entire code
for /f "tokens=5" %%i in ('Netsh WLAN show profile') do ^
set WifiName=%%i
Netsh WLAN show profile name= %WifiName% key='clear'
for /f "tokens=*" %%i in ('Netsh WLAN show profile name= %WifiName% key"=""clear"') do ^
echo "%%i"
pause
CodePudding user response:
You need to escape the =
in the for
loop. Here is a working example for you.
@echo off
for /f "tokens=2*delims=:" %%a in ('netsh wlan show profile ^|find /i "All User Profile"') do (
for /f "tokens=2*delims=:" %%i in ('netsh wlan show profile name^=%%a key^=clear ^| findstr /C:"Key Content"') do echo Wifi: %%a pass: %%i
)
As you can see by my example, the second for
is being run for each metavariable from the previous for
. In your example (though not working) you set all the variables and only the last one is being used.