3

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
05x
  • 81
  • 1
  • 1
  • 9
  • Would `for /f "tokens=4*" %%a in ('netsh wlan show hostednetwork setting^=security') do set "key=%%b"` work for your evil purposes? It's probably not locale-agnostic, but should work if you're reasonably certain your users will all be running English Windows. – rojo May 24 '17 at 13:05
  • thanks for your fast reply, but your solution didn't worked for me. I post my solution in the edit. – 05x May 24 '17 at 13:52
  • please don't post a solution into the question. Add an answer instead (and accept it) – Stephan May 24 '17 at 14:06
  • ohh..sorry, i am new in this community. I'll change it! – 05x May 24 '17 at 14:08
  • Please include your (failed) attempty in your question! – aschipfl May 24 '17 at 17:12
  • i added it to my question – 05x May 24 '17 at 17:31

1 Answers1

2

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
05x
  • 81
  • 1
  • 1
  • 9
  • 1
    Glad you got it working. We call the `^` character a caret. You're right that a circumflex is probably more accurate in typography and linguistics, since a circumflex is superscript (above the line) whereas a caret is subscript (below the line). However, programmers / scripters are too lazy to type circumflex. Caret is easier to spell. Anyway, +1. – rojo May 24 '17 at 14:54
  • thanks for the plus and the additional info. so far i just knew it as circumflex, but from now on i'll call it caret. It's really easier to write and speak. – 05x May 24 '17 at 16:20