05x
05x

Reputation: 91

Save a specific field from output into a variable on windows CMD

I want to read the wlan-key from netsh wlan show hostednetwork setting=security and save it in a variable so i can display it without the unneeded information like..:

echo your key is %wlan_key%

I already googled the problem on my own and found a similar topic. I used the approach from James A Mohler and tried to adapt it to my problem but it doesn't worked. failed attempt:

for /f "tokens=1-2 delims=:" %%a in ('netsh wlan show hostednetwork setting=security^|find "  Benutzer"') do set key=%%b
set key=%key:~1%
echo %key%
pause

Upvotes: 3

Views: 746

Answers (1)

05x
05x

Reputation: 91

I just forgot a simple circumflex between setting=security. For my solution i just adapted the above mentioned code.

for /f "tokens=1-2 delims=:" %%a in ('netsh wlan show hostednetwork setting^=security^|find "  Benutzer"') do set key=%%b
set key=%key:~1%
echo %key%
pause

Upvotes: 2

Related Questions