I am trying to get all known WiFi SSIDs including the Password.
When I use the following script, I can't get it to work to set the SSIDs in doublequotes, (so blanks and so on are correctly used).
Also when I've got special characters like exclamation marks, they dissapear.
Can someone please help me?
@ECHO OFF
setlocal EnableExtensions DisableDelayedExpansion
color 02
netsh wlan show profiles | findstr /R /C:"[ ]:[ ]" > temp.txt
echo @echo off >> helper.bat
echo setlocal enabledelayedexpansion >> helper.bat
echo for /f "tokens=5*" %%%%i in (temp.txt) do ( set val=%%%%i %%%%j >> helper.bat
echo if "!val:~-1!" == " " set val=!val:~2,-1! >> helper.bat
echo echo !val! ^>^> final.txt) >> helper.bat
echo for /f "tokens=*" %%%%i in (final.txt) do @echo SSID: %%%%i ^>^> others_%computername%.txt ^& echo # ================================================ ^>^> others_%computername%.txt ^& netsh wlan show profiles name=%%%%i key=clear ^| findstr /N /R /C:"[ ]:[ ]" ^| findstr 33 ^>^> others_%computername%.txt ^& echo # ================================================ ^>^> others_%computername%.txt ^& echo # Key content is the password of your target SSID. ^>^> others_%computername%.txt ^& echo # ================================================ ^>^> others_%computername%.txt >> helper.bat
REM echo del /f /q temp.txt final.txt >> helper.bat
echo exit >> helper.bat
start "" /wait helper.bat
exit
Output is for example: Original (temp.txt):
Profil fr alle Benutzer : 1FRITZ!Box Fon WLAN 7390
Output in final.txt:
1FRITZBox Fon WLAN 7390
What it should look like in final.txt:
"1FRITZ!Box Fon WLAN 7390"
Here is your original code complete with unnecessary things removed, fixes, and improvements. It no longer writes additional files, or defines variables. This should mean that
echoing of some characters won't affect your output, and therefore doublequoting the passphrase is unnecessary.Please note, I do not recommend that others should use this methodology, as proof would be needed that
netsh.exewill always output the target string, on the same line on all systems.