locked
Wlan Batch Script RRS feed

  • Question

  • Hey Guys,

    I am busy writing a Batch script that will present you with a list of wireless networks saved on your PC, you there select the network and it will display the password

    Here's what i have so far tested and working the part i can't do is get the script to run the

    netsh wlan show profile name="profilename" key="clear

    Heres what i got so far.

    @ECHO OFF
    setlocal enabledelayedexpansion
    
    REM Main Menu
    :Menu
    CLS
    Color 0A
    Echo.
    Echo.
    Echo  Windows Wifi Profile Viewer
    Echo  ==================================
    Echo.
    Echo   Select Operation:
    Echo.
    Echo    1^> View Wifi profiles.
    Echo    2^> Export Profiles to seperate files.
    Echo    3^> Exit
    Echo.
    SET "cho="
    SET /P "cho=   Select: "
    IF /I "%cho%" == "1" Goto :VProfile
    IF /I "%cho%" == "2" Goto :ExportPro
    IF /I "%cho%" == "3" Goto :EOF
    CLS
    Color 0C
    Echo.&Echo.&Echo.&Echo   Error! , No Such Option.
    Ping Localhost -n 4 >NUL
    GOTO :Menu
    
    REM ===============[ View Profiles ]===============
    
    :VProfile
    CLS
    Set i=1
    for /f "skip=9 tokens=1-4* delims= " %%A in ('netsh wlan show profile') Do (
    	SET "Line=%%A %%B %%C %%D %%E"
    	SET array[!i!]=%%E
    	SET /a i+=1
    )
    set n=%i%
    
    SET /a UBound=i-1
    Echo  ==================================
    Echo.
    Echo   Select WiFi Profile:
    Echo
    Echo  ==================================
    for /l %%i in (1,1,%UBound%) Do (
        echo     %%i^>. !array[%%i]!
    )
    Echo.
    Echo  ==================================
    
    SET /P "i=   Select: "
    for /L %%i in (%i%,1,%i%) Do (
    		echo !array[%%i]!
    REM INSERT POSSIBLE SOLUTIONS HERE ) Pause REM ===============[ \View Profiles ]===============

    Tuesday, June 23, 2015 5:13 PM

Answers

  • Netsh appears to do some funny things which clash with the equally funny way that convoluted batch files work. To work around the problem, direct the netsh output to a temporary file like so:

    @ECHO OFF
    netsh wlan show profile name=wombat key=clear > "%temp%\netsh.txt"
    for /F "delims=" %%a in ('type "%temp%\netsh.txt"') do echo %%a

    • Marked as answer by Swiftzn Tuesday, June 23, 2015 7:14 PM
    Tuesday, June 23, 2015 6:09 PM

All replies

  • Netsh appears to do some funny things which clash with the equally funny way that convoluted batch files work. To work around the problem, direct the netsh output to a temporary file like so:

    @ECHO OFF
    netsh wlan show profile name=wombat key=clear > "%temp%\netsh.txt"
    for /F "delims=" %%a in ('type "%temp%\netsh.txt"') do echo %%a

    • Marked as answer by Swiftzn Tuesday, June 23, 2015 7:14 PM
    Tuesday, June 23, 2015 6:09 PM
  • ahh alrighty i was looking at avoiding that but seems that might be the only option.

    Thanks for the feedback 

    PS any Code refinements?

    • Edited by Swiftzn Tuesday, June 23, 2015 6:17 PM
    Tuesday, June 23, 2015 6:17 PM
  • PS any Code refinements?

    Since you appear to be well up to speed with regards to batch programming, my suggestions would be matters of preference rather than substantial improvements.

    Please remember to mark my respons as "Answer" to this thread.

    Tuesday, June 23, 2015 6:38 PM