1
netsh wlan show profiles > profile.txt
for /f "skip=9" token=2 delims=:" %i in (profile.txt) do set "var=%i"
netsh wlan show profile name=%var% key=clear

now this command works if only one SSID is there, it shows all the details of that SSID. But if more than one SSID is there than it shows the detail of the last one SSID.

How to change the code to get all the SSID detail at once.

2 Answers2

0

Because you are not using a block of code you are over-writing the variable, finally leaving the last value and processing it. Instead use a block for your do:

netsh wlan show profiles > profile.txt

for /f "skip=9" token=2 delims=:" %i in (profile.txt) do (
    set "var=%i"
    netsh wlan show profile name=%var% key=clear)
Geoff
  • 151
  • 8
0

First of all, you should execute this batch under admin rights to show all the passwords in clear mode.

Second to solve your issue , you should populate your data into array like this code below :

@echo off & setlocal enabledelayedexpansion & color 0A
Title %~n0 to get SSID With details
::::::::::::::::::::::::::::::::::::::::::::
:: Automatically check & get admin rights ::
::::::::::::::::::::::::::::::::::::::::::::
Set TmpLogFile=%tmp%\TmpLog.txt
If Exist %TmpLogFile% Del %TmpLogFile%
REM  --> Check for permissions
Reg query "HKU\S-1-5-19\Environment" >%TmpLogFile% 2>&1
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
Echo.
ECHO                      ****************************************
ECHO                      ^| Running Admin shell... Please wait...^|
ECHO                      ****************************************

    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
::::::::::::::::::::::::::::
::START
::::::::::::::::::::::::::::
Set "TmpLog=%~dp0%~n0_Tmp.txt"
Set "Log=%~dp0%~n0.txt"
If Exist "%TmpLog%" Del "%TmpLog%"
If Exist "%Log%" Del "%Log%"
rem Populate the array
Set i=0
for /f "skip=1 tokens=2 delims=:" %%a in ('netsh wlan show profiles ^|find /i "Profil"') do (
    set /A i+=1
    set "list[!i!]=%%a"
)
set SSID=%i%
rem Display array elements for SSID List
cls
for /L %%i in (1,1,%SSID%) do (
    echo(
    echo SSID number %%i: "!list[%%i]:~1!!" 
    echo(
)
pause
rem Display array elements for SSID List with details
cls
for /L %%i in (1,1,%SSID%) do (
    echo(
    echo SSID number %%i: "!list[%%i]:~1!!" 
    echo(
    netsh wlan show profiles "!list[%%i]:~1!!" key=clear
    netsh wlan show profiles "!list[%%i]:~1!!" key=clear >> "%TmpLog%"
)
Cmd /U /C Type "%TmpLog%" > "%Log%"
If Exist "%TmpLog%" Del "%TmpLog%"
Start "" "%Log%"
pause
exit /b

Another batch file to show all your SSID with their passwords :

@echo off & setlocal enabledelayedexpansion
Title  WiFi Password Recovery
Mode con cols=70 lines=20
cls & color 0A & echo.
ECHO                  **************************************
echo                         WiFi Password Recovery
ECHO                  **************************************
echo.
if _%1_==_payload_  goto :payload

:getadmin
    echo                    %~nx0: elevating self
    set vbs=%temp%\getadmin.vbs
    echo Set UAC = CreateObject^("Shell.Application"^)                >> "%vbs%"
    echo UAC.ShellExecute "%~s0", "payload %~sdp0 %*", "", "runas", 1 >> "%vbs%"
    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
goto :eof

:payload
echo                        "SSID" ====^> "Password"
echo "SSID" ====^> "Password" > "%~dp0PassWifi.txt"
for /f "delims=: tokens=1,2" %%a in ('netsh wlan show profiles') do (
    if not "%%b"=="" (
        set ssid=%%b
        set ssid=!ssid:~1!
        call :getpass "!ssid!"
    )
)
del %temp%\tmp.txt
echo.
echo.
echo Done
If Exist "%~dp0PassWifi.txt" start "" "%~dp0PassWifi.txt"
pause>nul
exit /b

:getpass %1
set name=%1
set name=!name:"=!
netsh wlan show profiles %1 key=clear |find ":" > %temp%\tmp.txt
for /f "delims=: tokens=1,2" %%a in (%temp%\tmp.txt) do set passwd=%%b
set passwd=!passwd:~1!
echo                 "!name!" ====^> "!passwd!"
echo "!name!" ====^> "!passwd!" >> "%~dp0PassWifi.txt"
exit /b
Hackoo
  • 18,337
  • 3
  • 40
  • 70