;; 
;;====================================================================== 
;; 
;;FUNCTION       WirelessNetworkInfo() 
;; 
;;ACTION         Returns the Wireless Network configuration data  
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.0  - 2015/09/09 
;; 
;;HISTORY        1.0  - 2015/09/09 - Initial release 
;; 
;;SYNTAX         WirelessNetworkInfo([WorkDir]) 
;;                
;;PARAMETERS     WorkDir - OPTIONAL - String - path to working folder, defaults 
;;               to %TEMP% if not specified. 
;; 
;;REMARKS         
;; 
;;RETURNS        Array 
;; 
;;DEPENDENCIES   NetSH 
;; 
;;TESTED WITH    Vista, Win7, Win8, W2K8, W2K12 
;; 
;;EXAMPLES        
; 
Function WirelessNetworkInfo(OPTIONAL $_WorkDir)
 
  Dim $_Rc					; temp return code var 
  Dim $_Cmd					; WMIC command to execute 
  Dim $_aResult[0], $_I				; result array, index pointer 
  Dim $_D, $_aRec[4]				; data line, record array 
  Dim $_File, $_Fp				; working file, file pointer 
  Dim $_fSSID, $_fMSM				; flag values 
 
  $_fSSID = 0
  $_fMSM  = 0
  $_I     = -1
 
  $_Fp = FreeFileHandle()
  If $_Fp = 0
    Exit 87					; no resources available 
  EndIf
 
  If Not $_WorkDir $_WorkDir = '%TEMP%' EndIf
 
  $_Cmd = '%COMSPEC% /C netsh wlan export profile key=clear folder=' + $_WorkDir + '\_Wireless_ 2>NUL: 1>NUL:'
  MD $_WorkDir + '\_Wireless_'			; create work folder 
  Shell $_Cmd
 
  $_File = Dir($_WorkDir + '\_Wireless_\*.xml')
  While Not @ERROR
    If Open($_Fp, $_File, 0) = 0
      $_D = ReadLine($_Fp)
      While Not @ERROR
        Select
         Case Trim($_D) = '<SSID>'
          $_fSSID = 1
         Case Trim($_D) = '</SSID>'
          $_fSSID = 0
         Case Trim($_D) = '<MSM>'
          $_fMSM = 1
         Case Trim($_D) = '</MSM>'
          $_fMSM = 0
 
         Case $_fSSID And InStr($_D, '<name>')
          $_aRec[0] = Split(Split($_D, '<name>')[1], '</name>')[0]
 
         Case $_fMSM And InStr($_D, '<authentication>')
          $_aRec[1] = Split(Split($_D, '<authentication>')[1], '</authentication>')[0]
 
         Case $_fMSM And InStr($_D, '<encryption>')
          $_aRec[2] = Split(Split($_D, '<encryption>')[1], '</encryption>')[0]
 
         Case $_fMSM And InStr($_D, '<keyType>')
          $_aRec[3] = Split(Split($_D, '<keyType>')[1], '</keyType>')[0]
 
         Case $_fMSM And InStr($_D, '<keyMaterial>')
          $_aRec[4] = Split(Split($_D, '<keyMaterial>')[1], '</keyMaterial>')[0]
 
        EndSelect
        $_D = ReadLine($_Fp)
      Loop
      $_Rc = Close($_Fp)
      $_I = $_I + 1
      ReDim Preserve $_aResult[$_I]
      $_aResult[$_I] = $_aRec
    EndIf
    $_File = Dir()
  Loop
 
  RD $_WorkDir + '\_Wireless_' /s 		; clean up & remove work folder 
  $WirelessNetworkInfo = $_aResult
  Exit 0
 
EndFunction