1

I am thanks to this (german) site aware of the batch command

netsh wlan show profile 

to show the names of all safed WiFi networks like this:

...
Benutzerprofile
---------------
    Profil fr alle Benutzer : <wifi network name 1>
    Profil fr alle Benutzer : <wifi network name 2>
...

After that, one can use

netsh wlan show profile <Name> key=clear

where <Name> stands for the name of the respective network gained e.g. above.

Is it possible to automatically combine the two?

Cadoiz
  • 1,446
  • 21
  • 31
  • Give a try for this batch tested on french machines [Wifi Passwords Recovery.bat](https://pastebin.com/Ntc8SZLU) – Hackoo Feb 24 '20 at 15:16

3 Answers3

2

This is one I did a while back and does not need delayedexpansion

@echo off
setlocal enabledelayedexpansion
for /f "tokens=2delims=:" %%a in ('netsh wlan show profile ^|findstr ":"') do (
    set "ssid=%%~a"
    call :getpwd "%%ssid:~1%%"
)
:getpwd
set "ssid=%*"
for /f "tokens=2delims=:" %%i in ('netsh wlan show profile name^="%ssid:"=%" key^=clear ^| findstr /C:"Key Content"') do echo ssid: %ssid% pass: %%i
Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • 1
    @jeb Thanks for the edit, my damn keyboard always capitalises stand alone I :) – Gerhard Feb 24 '20 at 16:09
  • 1
    Works for all my Wifi's with some strange names, but it's not language independent. The first `FIND` can be changed to `findstr ":"`, that should work with the most languages. Only the second one seems to be a bit tricky – jeb Feb 24 '20 at 16:09
  • @jeb yeah true, let me think of some language independent ways – Gerhard Feb 24 '20 at 16:12
  • 1
    Your `call :getpwd %%ssid:~1%%` seems to be risky for content like `&|<>` and so on. And it seems to be [allowed in SSID names](https://stackoverflow.com/a/28450037/463115)! Luckily, I don't have such names, until now – jeb Feb 24 '20 at 16:14
  • 1
    @jeb made the change for the possible special characters. Will spend some time later to make this language independent. – Gerhard Feb 24 '20 at 17:10
0

For the for a bit below and the :Trim part (thanks to 1 or 2), delayed expansion is needed to make the variables within this batch file be expanded at execution time rather than at parse time. Usage: variables delimited by exclamation marks (!) are evaluated on execution. This will ensure the correct behavior in this case.

echo|set /p="test text" gives a text without newline (thanks).

for /F "tokens=2 delims=:" %%i in (SavedNetworks.temp) do (...) gives you the second token each line, seperated by a : (source).

SetLocal EnableDelayedExpansion
@echo|set /p="Lese die existierenden Netzwerke ein:"
netsh wlan show profile > SavedNetworks.temp
@echo|set /p="Verarbeite die eingelesenen Netzwerke (1):"
@echo off
for /F "tokens=2 delims=:" %%i in (SavedNetworks.temp) do (
call :Trim Actual %%i
netsh wlan show profile "!Actual!" key=clear >> SavedNetworks2.temp 
) 
@echo on
move SavedNetworks2.temp SavedNetworks.temp 
@echo|set /p="Verarbeite die eingelesenen Netzwerke (2):"
findstr "SSID-Name Sicherheitsschlssel Schlsselinhalt" SavedNetworks.temp >> SavedNetworks.txt
::notepad SavedNetworks.temp 
del SavedNetworks.temp 
notepad SavedNetworks.txt
::pause
exit /b

:Trim
::Line below already at the top.
::SetLocal EnableDelayedExpansion
set Params=%*
for /f "tokens=1*" %%a in ("!Params!") do EndLocal & set %1=%%b
exit /b

Unfortunately, this script does not work for all languages, namely here: findstr "SSID-Name Sicherheitsschlssel Schlsselinhalt" SavedNetworks.temp >> SavedNetworks.txt (found it here, command and output are the german version). To find the right words for your language, uncomment ::notepad SavedNetworks.temp and put a :: in front of the next line. Run it and replace "SSID-Name Sicherheitsschlssel Schlsselinhalt" fittingly.

Cadoiz
  • 1,446
  • 21
  • 31
  • 2
    It misses all SSID's with an exclamation mark! That's all `FRITZ!Box ...` WiFi's – jeb Feb 24 '20 at 16:01
0

Here's how I wrote it:

File: ShowWiFi.bat

@echo off
setlocal enabledelayedexpansion

for /F "tokens=2 delims=:" %%a in ('netsh wlan show profile') do (
    set wifi_pwd=
    for /F "tokens=2 delims=: usebackq" %%F IN (`netsh wlan show profile %%a key^=clear ^| find "Key Content"`) do (
        set wifi_pwd=%%F
    )
    echo %%a : !wifi_pwd!
)

Example Output

C:\>ShowWiFi
 Fiber5G :  SomePassword
 Courtyard_GUEST :
 redroof :
 Axon :  Password2
 Taco Bell WiFi :
 abelenkWiFi :  January
 SPS Internal :
C:\>

This didn't show all passwords for some reason, but did show many of them.

abelenky
  • 63,815
  • 23
  • 109
  • 159
  • 3
    This fails for SSID's with spaces, like your own example shows for `Taco Bell WiFi`. You have to use `nestsh wlan show profile name="%%a" key=clear`. It still fails for SSID's with exclamation marks – jeb Feb 24 '20 at 15:49