C:\_G\WWW\~ELISANET\INFO\tscmd199.html
<https://www.salminet.fi/info/tscmd199.html>
Copyright © 2003- by Prof. Timo Salmi  
Last modified Mon 28-Sep-2026 11:25:53

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.



199} How do I get the Wi-Fi password of the current WLAN connection?

Using ordinary cmd.exe commands:
  @echo off & setlocal enableextensions
  call :GetSSID ssid_
  echo %%ssid_%%=%ssid_%
  call :GetSSIDpass "%ssid_%" ssidpass_
  echo %%ssidpass_%%=%ssidpass_%
  endlocal & goto :EOF

  :GetSSID
  setlocal enableextensions
  set return_=
  netsh wlan show interface | find /i "is not running" > nul
  if %errorlevel% EQU 0 (
    set return_=WLAN not detected
    goto _eofGetSSID)
  set return_= found an ssid
  for /f "tokens=2 delims=:" %%a in (
    'netsh wlan show interface ^| find /i " SSID"') do set return_=%%a
  set return_=%return_:~1,255%
  :_eofGetSSID
  endlocal & set "%1=%return_%" & goto :EOF

  :getSSIDpass
  setlocal enableextensions
  set tempfile_=%temp%\getSSIDpass$$$.tmp
  set return_=
  netsh wlan show profile name="%~1" key=clear | find /i " Key Content" > "%tempfile_%"
  for /f "tokens=2 delims=:" %%a in (
    'type "%tempfile_%"') do set return_=%%a
  del "%tempfile_%"
  :: Effectively, in this task, remove the leading blank
  for /f "tokens=* delims= " %%a in ("%return_%") do set "return_=%%a"
  endlocal & set "%2=%return_%" & goto :EOF

The output might be e.g.
  C:\_M>C:\_D\TEST\CMSFAQ.CMD
  %ssid_%=MyWiFi
  %ssidpass_%=MyWiFiPassword

[Previous] [Next]

C:\_G\WWW\~ELISANET\INFO\tscmd199.html
C:\_G\WWW\~ELISANET\FTPCMD\TSALMI.CMD /tscmd199
C:\_E\ARCZIP\COPYTONE.CMD /~info
https://www.salminet.fi/info/tscmd199.html
file:///c:/_g/www/~elisanet/info/tscmd199.html