Save all wifi passwords stored on a Windows device into an output txt file. ("wifiPassOutput.txt")
You can run the batch file from any directory, including removable drives. It does not require admin priveledges. When you first run the batch file, it will create a file called "wifiPassOutput.txt" as well as display its output in the terminal.
- Disable echo (printing out each command before running them)
@echo off-
Overwrite "wifiPassOutput.txt" with a header containing the device/computer name, real fancy stuff.
>is used to overwrite files while>>is used to append (add to the end of) files; this process is called redirection.echo. >> wifiPassOutput.txtappends an empty line to "wifiPassOutput.txt"
echo =================================================== > wifiPassOutput.txt
echo Network Keys (wifi passwords) stored on %ComputerName% >> wifiPassOutput.txt
echo =================================================== >> wifiPassOutput.txt
echo. >> wifiPassOutput.txt- Not sure why, but this line allows for loops to work.
setlocal EnableDelayedExpansion-
netsh wlan show profile(Network Shell Wireless Local Area Network show profile) will display the name of each wifi network a computer has previously connected to.This is piped (the output is used as an input to) into a
findstr(find string) which filters out lines starting with" All User Profile : ".Then this is redirected into a temporary file "a.txt".
netsh wlan show profile | findstr /C:" All User Profile : " > a.txt-
For loops are declared using
for(duh)./findicates that the loop will iterate through a file's contents."delims="means no delimiter (character that separates each string in the file) will be used, meaning the loop will iterate through each line, "storing" it as parameter%%ain(a.txt).
for /f "delims=" %%a in (a.txt) DO (-
Each line will be saved as variable
xbecause substrings cannot be made from parameters.!x:~27!is a substring ofxwith the first 27 characters (" All User Profile : ") removed so that it is just the network name by itself.echo Network: !x:~27! >> wifiPassOutput.txtappends the word "Network: " and the network name to "wifiPassOutput.txt".
set x=%%a
echo Network: !x:~27! >> wifiPassOutput.txt-
netsh wlan show profile "!x:~27!" key=clearwill display various information about the network, specified by"!x:~27!", stored on the computer.This is piped into a
findstrfor" Key Content :"which is the line of information containing the wifi password.This is redirected into another temporary file "b.txt".
||makes the following command run if the previous one encounters an error, eg. there is no line containing the words" Key Content :". This usually happens on school networks.If a network has no "password" append
Key: noneto "wifiPassOutput.txt".
netsh wlan show profile "!x:~27!" key=clear | findstr /C:" Key Content :" > b.txt || (echo Key: none >> wifiPassOutput.txt)-
For each line in "b.txt", append the word "Key: " and the wifi password to "wifiPassOutput.txt".
Add an empty line and close the outside for loop.
for /f "delims=" %%b in (b.txt) DO (
set y=%%b
echo Key: !y:~28! >> wifiPassOutput.txt
)
echo. >> wifiPassOutput.txt
)-
Delete the temporary files "a.txt" and "b.txt".
Print out the contents of "wifiPassOutput.txt".
Print an empty line then pause (create an "Press any key to continue..."). Pressing any key will make the script finish and close.
del a.txt
del b.txt
type wifiPassOutput.txt
echo.
pause