Page 1 of 2

My Wifi Keys (fr-uk-de compatible)

Posted: Thu Sep 23, 2021 8:09 am
by ar-s
Image

Hi there,

I propose you a small software that I made to display the wifi keys registered in a local network.
I made it because when I go to my customers, either they don't know the wifi key and have to look for it in the box interface or behind the box, or the key is 3miles long which makes me waste time.
So this little software will show you the key of the SSID of your local network and will copy it in the clipboard.

UPDATE v1.01
Should now work with english, german or french windows.


- Windows Only

Notes
- Wifi connection must be your primary connection
- You must have a wifi interface (or wifi usb key connected)
- The service : WLAN auto config service must be at least on "automatic" (which is logically the case).
Thanks for your feedback.

Translated with www.DeepL.com/Translator (free version)

Download : MyWifi.zip

Code: Select all

; My Wifikeys
; My Wifikeys
; By Ar-S // 2021-09-21
; v1.01 adding english findstring strings.
; Thanks to Barry - Englsih keyword
; Thanks Cyllceaux - Deutch keyword

NewList ssid.s()

; Catch SSID
param$ = "wlan show profiles"
p=RunProgram("netsh",param$,"",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read|#PB_Program_Error)

If p
    
    While ProgramRunning(p)
        If AvailableProgramOutput(p)
            t$ = ReadProgramString(p)
            n1=FindString(t$,":")
            If n1
                n2=Len(t$)
                r$=Mid(t$,n1+1,n2-n1)
                AddElement (ssid())
                ssid() = r$
             EndIf
        EndIf
        err$ = ReadProgramError(p)
        If err$
            o$+"<ERR> " + err$ +#CRLF$
        EndIf
    Wend
    
    CloseProgram(p)

EndIf


If ListSize (ssid()) = 0
    MessageRequester("Erreur","No wifi is connected on this machine or it is not the main connection."+Chr(10)+"This program will end",0)
    End
EndIf

If OpenWindow(0, 0, 0, 360, 60, "LDV MULTIMEDIA MY WIFIKEYS v1.01", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    GO = 0
    ComboBoxGadget(1,1,1,358,30)
    ForEach ssid()
        AddGadgetItem(1, -1, ssid() )
    Next
    RemoveGadgetItem(1,0)
    
    SetGadgetState(1,0)
    StringGadget(2,1,32,358,30,"",#PB_String3D_ReadOnly)
    
    
    Repeat
        Event = WaitWindowEvent()
        
        
        Select EventGadget()
            Case 1
                
                If EventType() = #PB_EventType_Change
                    ssid$ = GetGadgetText(1)
                    param$="wlan show profile name="+Chr(34)+Trim(ssid$)+Chr(34)+" key=clear"
                    p2=RunProgram("netsh",param$,"",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read|#PB_Program_Error)
                    
                    If p2
                        r2$ = ""
                        
                        While ProgramRunning(p2)
                            If AvailableProgramOutput(p2)
                                t$ = ReadProgramString(p2)+#CRLF$
                                FR = FindString(t$,"Contenu de la cl",1,#PB_String_NoCase) ; français
                                UK = FindString(t$,"key content",1,#PB_String_NoCase)      ; English
                                DE = FindString(t$,"sselinhalt",1,#PB_String_NoCase)       ; Deutch
                                
                                If FR <> 0
                                    r2$ = t$
                                ElseIf  UK <> 0
                                    r2$ = t$
                                ElseIf DE <> 0
                                     r2$ = t$   
                                EndIf
                                
                                
                                If r2$ <> ""
                                    n1=FindString(r2$,":")
                                    n2=Len(r2$)
                                    r2$=Mid(r2$,n1+1,n2-n1)
                                Else
                                    r2$ = "No active wifi detected :[ "
                                EndIf
                                
                            EndIf
                            err$ = ReadProgramError(p2)
                            If err$
                                o$+"<ERR> " + err$ +#CRLF$
                            EndIf
                        Wend
                        
                        CloseProgram(p2)

                    Else
                        Debug "erreur"
                    EndIf
                    SetGadgetText(2,"Wifi key : "+ r2$)
                    SetClipboardText(r2$)
                EndIf
                
        EndSelect
    Until Event = #PB_Event_CloseWindow
EndIf


Re: My Wifi Keys

Posted: Fri Sep 24, 2021 5:17 am
by Denis
Vraiment Sympa!

Image

Re: My Wifi Keys

Posted: Fri Sep 24, 2021 8:40 am
by BarryG
ar-s wrote: Thu Sep 23, 2021 8:09 amWLAN automatic configuration service must be at least on "automatic"
Where do I find this setting in my router? What name should I search for?

Because your code doesn't reveal any keys for me:

Image

I have a Netgear router and my PC connects to it via wi-fi only (no ethernet cable).

Re: My Wifi Keys

Posted: Fri Sep 24, 2021 8:50 am
by firace
BarryG wrote: Fri Sep 24, 2021 8:40 am
ar-s wrote: Thu Sep 23, 2021 8:09 amWLAN automatic configuration service must be at least on "automatic"
Where do I find this setting in my router? What name should I search for?

Because your code doesn't reveal any keys for me:

Image

I have a Netgear router and my PC connects to it via wi-fi only (no ethernet cable).
This is a Windows service.

Re: My Wifi Keys

Posted: Fri Sep 24, 2021 8:55 am
by BarryG
firace wrote: Fri Sep 24, 2021 8:50 amThis is a Windows service.
Is it this one?

Image

Re: My Wifi Keys

Posted: Fri Sep 24, 2021 9:26 am
by firace
BarryG wrote: Fri Sep 24, 2021 8:55 am
firace wrote: Fri Sep 24, 2021 8:50 amThis is a Windows service.
Is it this one?
Yes I think so. @ar-s please can you confirm?

Re: My Wifi Keys

Posted: Fri Sep 24, 2021 9:48 am
by Marc56us
Hi,

If the interface does not display anything (no error), it means that the default connection is not on the WiFi card, but on another one (network cable)

This program show the password of the active connection only (default connection).
Of course this works only if your are connected on this connection.
It is likely that an admin account is required ?

As seen on RunProgram line, this send command line:

Code: Select all

netsh wlan show profile name=<SSID WiFi> key=clear
Edit: After testing in different cases (Wifi card on/off and internet connection on/off) I get different results.
I have a cable (fiber) and Wifi connection and can switch from one to the other.

:wink:

Re: My Wifi Keys

Posted: Fri Sep 24, 2021 10:20 am
by BarryG
I tried with and without admin rights, and still no key is shown; and it's definitely wi-fi to my current online connection. Maybe it's a router security thing; I don't know. I don't know how networks work. If anything, it shows the code can't be relied upon, because if I were one of ar-s's customers, I'd be saying "it's not showing any key" and frustrating him. Hehe.

Re: My Wifi Keys

Posted: Fri Sep 24, 2021 10:23 am
by Cyllceaux
the problem is this line:

Code: Select all

If FindString(t$,"Contenu de la cl")
for german it is:

Code: Select all

If FindString(t$,"sselinhalt")
you have to change it for your language

Re: My Wifi Keys

Posted: Fri Sep 24, 2021 10:24 am
by BarryG
Change it to what? I don't know what to put there.

Re: My Wifi Keys

Posted: Fri Sep 24, 2021 10:24 am
by Marc56us
Same thing if you use command ligne version in CMD ?
C:\> netsh wlan show profile name=<SSID WiFi> key=clear
replace <SSID WiFi> with your SSID

PS. For PB Windows english version:

Code: Select all

If FindString(t$,"Key Content")    ;     "Contenu de la cl")

Re: My Wifi Keys

Posted: Fri Sep 24, 2021 10:48 am
by Cyllceaux
oh... and this line

Code: Select all

param$="wlan show profile name="+ssid$+" key=clear"
to

Code: Select all

param$=~"wlan show profile name=\""+Trim(ssid$)+~"\" key=clear"

Re: My Wifi Keys

Posted: Fri Sep 24, 2021 10:58 am
by BarryG
This is how I finally got it to work with my SSID. Don't forget SSIDs can have spaces, so you may need to wrap it in quotes.

Code: Select all

NewList ssid.s()

; Catch SSID
param$ = "wlan show profiles"
p=RunProgram("netsh",param$,"",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read|#PB_Program_Error)

If p
  
  While ProgramRunning(p)
    If AvailableProgramOutput(p)
      t$ = ReadProgramString(p)
      n1=FindString(t$,":")
      If n1
        n2=Len(t$)
        r$=Mid(t$,n1+1,n2-n1)
        AddElement (ssid())
        ssid() = r$
      EndIf
    EndIf
    err$ = ReadProgramError(p)
    If err$
      o$+"<ERR> " + err$ +#CRLF$
    EndIf
  Wend
  
  CloseProgram(p)
  
  ;Debug r$
EndIf


If ListSize (ssid()) = 0
  MessageRequester("Erreur","No wifi Key on this computer"+Chr(10)+"This program will stop",0)
  End
EndIf

If OpenWindow(0, 0, 0, 360, 60, "LDV MULTIMEDIA MY WIFIKEYS", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  GO = 0
  ComboBoxGadget(1,1,1,358,30)
  ForEach ssid()
    AddGadgetItem(1, -1, ssid() )
  Next
  RemoveGadgetItem(1,0)
  
  SetGadgetState(1,0)
  StringGadget(2,1,32,358,30,"",#PB_String3D_ReadOnly)
  
  
  Repeat
    Event = WaitWindowEvent()
    
    
    Select EventGadget()
      Case 1
        
        If EventType() = #PB_EventType_Change
          ssid$ = GetGadgetText(1)
          param$="wlan show profile name="+Chr(34)+Trim(ssid$)+Chr(34)+" key=clear"
          p2=RunProgram("netsh",param$,"",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read|#PB_Program_Error)
          
          If p2
            
            While ProgramRunning(p2)
              If AvailableProgramOutput(p2)
                t$ + ReadProgramString(p2)+#CRLF$
              EndIf
            Wend
            If FindString(t$,ssid$)
              n1=FindString(t$,"key content",1,#PB_String_NoCase) ; For English Windows. Other languages miss out?
              If n1
                n2=FindString(t$,":",n1)
                If n2
                  key$=Trim(Mid(t$,n2+1))
                  cr=FindString(key$,#CR$)
                  If cr
                    key$=Left(key$,cr-1)
                  EndIf
                EndIf
              EndIf
            EndIf
            
            CloseProgram(p2)
            
          Else
            Debug "erreur"
          EndIf
          SetGadgetText(2,"Wifi key: "+ key$)
          SetClipboardText(key$)
        EndIf
        
    EndSelect
  Until Event = #PB_Event_CloseWindow
EndIf

Re: My Wifi Keys (fr-uk-de compatible)

Posted: Sat Sep 25, 2021 4:13 pm
by ar-s
Thanks for your feedback.

I have update the first code.
It should be working on french/english/german windows for now.

Re: My Wifi Keys (fr-uk-de compatible)

Posted: Sat Sep 25, 2021 6:34 pm
by ChrisR
It works here but I have a problem with accents éèà..., OEM characters
On cmd commands, Fryquez's solution works perfectly to convert OEM characters to Unicode, See Windows console with UNICODE

The latest cmd commands created by windows seem to support English as parameter like: Dism.exe /English
Too bad this switch is not implemented on the other cmd