Home > OS >  Show a specific part of a findstr
Show a specific part of a findstr

Time:10-16

This is a command to show the name of the connected Wi-Fi.

Netsh WLAN show interfaces | findstr Profile

Result :

Profile                : Mywifi_5G

How can I do to show just the "Mywifi_5G" ? Like this :

Mywifi_5G

I need it because I want to put the result into a variable of a Batch File.

CodePudding user response:

See if this helps... I Tried the Code given here but it didnt work for me... Anyways you try it out..https://devblogs.microsoft.com/oldnewthing/20120731-00/?p=7003#comments

CodePudding user response:

Thanks for tabby.sl's answer, I finished the script.

It is to get the SSID and password of the connected Wi-Fi.

Batch Script :

@ECHO OFF
  
FOR /f "tokens=3" %%i IN ('netsh wlan show interfaces ^| findstr /C:"Perfil"') DO SET SSID=%%i

FOR /f "tokens=5" %%i IN ('netsh wlan show profile %SSID% key"="clear ^| findstr /C:"Chave"') DO SET PASSWORD=%%i

ECHO --------------------------------------------------------------------
ECHO.
ECHO            SSID : %SSID%
ECHO.
ECHO            PASSWORD : %PASSWORD%
ECHO.
ECHO --------------------------------------------------------------------

PAUSE

Notes : "Perfil" and "Chave" are words from cmd in Portuguese ( Brazil ).
Perfil = Profile
Chave = Key
The number in "tokens=" will depend of the system language.

  • Related