Sign in to follow this  
Followers 0
Strikers

Native WiFi Help

5 posts in this topic

Hi! I'm having problems to use NativeWifi. I was reading already over couple of forums but didnt get any solution.

I have a Wifi that is secured by certificate and domain user auth. To grant domainusers access is not a problem, but I have an Guest account that needs to be manually installed via Script at users Notebook.

... but I'm not getting the profile automatically created at all.

Here's my code so far:

#include "NativeWifi.au3"

;install certificate
Run("certmgr.exe -add WLAN-CA.cer -s -r currentUser Root", '', @SW_HIDE)
sleep(2000)
WinActivate("Sicherheitswarnung", "")
WinWaitActive("Sicherheitswarnung", "")
Send("!J")
;end install certificate


$fDebugWifi = True
_Wlan_StartSession()
_Wlan_StartNotificationModule()
Local $oProfile, $sReason
$oProfile = _Wlan_CreateProfileObject()
With $oProfile
.Name = "Testlan"
.SSID.Add($oProfile.Name)
.Type = "Infrastructure"
.Auth = "WPA2"
.Encr = "AES"
.Options.NonBroadcast = True
.Options.ConnMode = "Automatic"
.OneX.Enabled = True
.OneX.AuthMode = "User"
.PMK.PreAuthEnabled = True
.PMK.CacheEnabled = True
.EAP.BaseType = "PEAP"
.EAP.Type = "PEAP-MSCHAP"
.EAP.PEAP.MSCHAP.UseWinLogonCreds = False
EndWith
ConsoleWrite(_Wlan_ConvertProfile($oProfile) & @CRLF)
$oUserData = _Wlan_CreateUserDataObject()
With $oUserData
.BaseType = "PEAP"
.Type = "PEAP-MSCHAP"
.PEAP.MSCHAP.Username = "wlanuser"
.PEAP.MSCHAP.Password = "test2012"
.PEAP.MSCHAP.Domain = "lcldom"
EndWith
_Wlan_SetProfileUserData("ACS_WLAN", $oUserData, 1)
ConsoleWrite(_Wlan_ConvertUserData($oUserData) & @CRLF)

If Not _Wlan_SetProfile($oProfile, $sReason) Then
MsgBox(0, "Wifi", "Failed to create profile " & $oProfile.Name & ". @error=" & @error & @CRLF & "Because: " & $sReason)
Exit
EndIf
If _Wlan_Connect($oProfile.Name, True) Then ;the True means _Wlan_Connect will wait for the connection to either complete or fail before continuing
MsgBox(0, "Wifi", "Connected to " & $oProfile.Name & ".")
Else
MsgBox(0, "Wifi", "Connection failed to " & $oProfile.Name & ". @error=" & @error)
EndIf

Here the log from Autoit:

>"C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "Wlan Test.au3" /UserParams
+>15:19:08 Starting AutoIt3Wrapper v.2.1.0.33 Environment(Language:0407 Keyboard:00000407 OS:WIN_XP/Service Pack 3 CPU:X64 OS:X86)
>Running AU3Check (1.54.22.0) from:C:\Programme\AutoIt3
+>15:19:09 AU3Check ended.rc:0
>Running:(3.3.8.1):C:\Programme\AutoIt3\autoit3.exe "Wlan Test.au3"
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop

Result of: ConsoleWrite(_Wlan_ConvertProfile($oProfile) & @CRLF)

<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
<name>Testlan</name>
<SSIDConfig>
<SSID>
<name>Testlan</name>
</SSID>
<nonBroadcast>true</nonBroadcast>
</SSIDConfig>
<connectionType>ESS</connectionType>
<connectionMode>auto</connectionMode>
<MSM>
<security>
<authEncryption>
<authentication>WPA2</authentication>
<encryption>AES</encryption>
<useOneX>true</useOneX>
</authEncryption>
<PMKCacheMode>enabled</PMKCacheMode>
<preAuthMode>enabled</preAuthMode>
<OneX xmlns="http://www.microsoft.com/networking/OneX/v1">
<authMode>user</authMode>
<EAPConfig>
     <EapHostConfig xmlns="http://www.microsoft.com/provisioning/EapHostConfig"
     xmlns:eapCommon="http://www.microsoft.com/provisioning/EapCommon">
     <EapMethod>
     <eapCommon:Type>25</eapCommon:Type>
     <eapCommon:AuthorId>0</eapCommon:AuthorId>
     </EapMethod>
     <Config xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1"
     xmlns:msPeap="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV1"
     xmlns:eapTls="http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV1"
     xmlns:msChapV2="http://www.microsoft.com/provisioning/MsChapV2ConnectionPropertiesV1"
     xmlns:msPeapV2="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV2"
     xmlns:eapTlsV2="http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV2">
     <baseEap:Eap>
     <baseEap:Type>25</baseEap:Type>
     <msPeap:EapType>
         <msPeap:InnerEapOptional>false</msPeap:InnerEapOptional>
         <baseEap:Eap>
         <baseEap:Type>26</baseEap:Type>
         <msChapV2:EapType>
         <msChapV2:UseWinLogonCredentials>false</msChapV2:UseWinLogonCredentials>
         </msChapV2:EapType>
         </baseEap:Eap>
     </msPeap:EapType>
     </baseEap:Eap>
     </Config>
     </EapHostConfig>
</EAPConfig>
</OneX>
</security>
</MSM>
</WLANProfile>

!APIError @Ln[5303] _WinAPI_WlanSetProfileEapXmlUserData - Falscher Parameter.

Result of: ConsoleWrite(_Wlan_ConvertUserData($oUserData) & @CRLF)

<?xml version="1.0"?>
<EapHostUserCredentials xmlns="http://www.microsoft.com/provisioning/EapHostUserCredentials"
xmlns:eapCommon="http://www.microsoft.com/provisioning/EapCommon">
<EapMethod>
<eapCommon:Type>25</eapCommon:Type>
<eapCommon:AuthorId>0</eapCommon:AuthorId>
</EapMethod>
<Credentials xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapUserPropertiesV1"
xmlns:MsPeap="http://www.microsoft.com/provisioning/MsPeapUserPropertiesV1"
xmlns:eapTls="http://www.microsoft.com/provisioning/EapTlsUserPropertiesV1"
xmlns:MsChapV2="http://www.microsoft.com/provisioning/MsChapV2UserPropertiesV1">
<baseEap:Eap>
<baseEap:Type>25</baseEap:Type>
<MsPeap:EapType>
<baseEap:Eap>
     <baseEap:Type>26</baseEap:Type>
     <MsChapV2:EapType>
     <MsChapV2:Username>wlanuser</MsChapV2:Username>
     <MsChapV2:Password>test2012</MsChapV2:Password>
     <MsChapV2:LogonDomain>lcldom</MsChapV2:LogonDomain>
     </MsChapV2:EapType>
</baseEap:Eap>
</MsPeap:EapType>
</baseEap:Eap>
</Credentials>
</EapHostUserCredentials>

!APIError @Ln[5181] _WinAPI_WlanSetProfile - Das Profil mit den Netzwerkverbindungen ist fehlerhaft.
!Because: Die im Profil angegebenen EAP-Verbindungseigenschaften sind ungültig.
+>15:19:18 AutoIT3.exe ended.rc:0
>Exit code: 0 Time: 11.812

This is my exportet XML file from manually setting up the profile:

<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
<name>Testlan</name>
<SSIDConfig>
<SSID>
<hex>546573746C616E</hex>
<name>Testlan</name>
</SSID>
</SSIDConfig>
<connectionType>ESS</connectionType>
<MSM>
<security>
<authEncryption>
<authentication>WPA2</authentication>
<encryption>AES</encryption>
<useOneX>true</useOneX>
</authEncryption>
<OneX xmlns="http://www.microsoft.com/networking/OneX/v1">
<authMode>user</authMode>
<EAPConfig>
     <EapHostConfig xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
     <EapMethod>
     <Type xmlns="http://www.microsoft.com/provisioning/EapCommon">25</Type>
     <VendorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorId>
     <VendorType xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorType>
     <AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</AuthorId>
     </EapMethod>
     <ConfigBlob>01000000690000000100000001000000020000002E000000150000000100000014000000DE54AEBFAF8ABAA412910E1E5A7BED5BA09FB0B0000001000000170000001A0000000100000000000000000000000000000000000000000000000000000000000000000000</ConfigBlob>
     </EapHostConfig>
</EAPConfig>
</OneX>
</security>
</MSM>
</WLANProfile>

Hope somebody can help me to get this running.

Thanks!!

Share this post


Link to post
Share on other sites



Hey mate,

I did a quick test run of that script, and it all went through happily for me on windows 7 and XP. If you're running XP you will need this well hidden update for things to work properly though http://support.microsoft.com/kb/958071.

If thats not the problem, I suppose it has something to do with the non-english version of windows - could you let me know how you do?

thankyou,

Matt

Share this post


Link to post
Share on other sites

Hi Matt,

i was trieng a little more and the hotfix helped a little, but still having a problem of setting the credentials for the profile.

I tested now under Win 7 and Win XP, both can now create the Profiles, but won't pass the user information.

I changed my script and added some functions.

How can I check in my function DeleteProfile() that only if the Profile exists to execute it?

I attached you my script that i made so far.

The Console shows me also following errors:

!APIError @Ln[2516] _WinAPI_WlanDeleteprofile - Element nicht gefunden.
!APIError @Ln[5303] _WinAPI_WlanSetProfileEapXmlUserData - Falscher Parameter.

Anny help or suggestions to improve would be great!

Thanks!!

Wlan Test.au3

Share this post


Link to post
Share on other sites

I was just reading a bit more and I saw that the function to set the profile [ _Wlan_SetProfileUserData ] is in your Wifi40.au3, do I need to include this file too?

I changed my script again a bit, so I attach you my new version ;-)

I also attached you a picture of the files that i'm using / having in the same directory for including. Hope that these are all i need.

#Wlan Connection.au3

post-74871-0-12641200-1346402870_thumb.j

Share this post


Link to post
Share on other sites

Strikers,

Very sorry about the wait man -here we go.

Firstly, don't worry about wifi40.au3 - its already in NativeWifi.au3. Basically the idea was to seperate the all the raw API calls to anything specific to my take on the UDF. Thus NativeWifi.au3 consists of an API library (WlanAPI10), a UDF library (Wlan40) and constant definitions and such.

There probably isn't much point in checking for the profiles existance before attempting to remove it. the only way to really check is to use _Wlan_GetProfileList() or _Wlan_GetProfile(). Obviously you can't garantee either of them will succeed. If DeleteProfile() fails you can check @error and @extended to see if it was a permission problem or simply didn't exist.

If you really wan't to be pedantic and avoid red messages, you can call _Wlan_GetProfileList(). If there are no profiles, the function will fail because of a "nul" output ( @error 3 ) rather than an API error ( @error 2 ). :)

Lastly that "all users" flag in _WinAPI_WlanSetProfileEapXmlUserData is actually illegal in anything before Windows 7. Unfortunately I'm not too sure it's even works then - seems to be a bug in windows.

Otherwise the code looks pretty good!

Let me know if you still have problems with the connecting part - I'll try to be quicker with the turn-around.

Cheers,

Matt

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=Wlan Connection.exe
#AutoIt3Wrapper_Res_Comment=WLAN Connection for Domain Users
#AutoIt3Wrapper_Res_Description=WLAN Connection for Domain Users
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Strikers
#AutoIt3Wrapper_Res_Language=1031
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;############################################ au include's
#include "NativeWifi.au3"
#include <GuiButton.au3>
#include <GuiConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <File.au3>
;############################################ Variablen deklarieren
Local $wlan_name = "Testlan"
Local $msKB
;############################################ Dateien einbinden
FileInstall("certmgr.exe", @TempDir & "certmgr.exe", 1)
FileInstall("EMT-WLAN-CA.cer", @TempDir & "EMT-WLAN-CA.cer", 1)
FileInstall("WindowsXP-KB958071-x86-DEU.exe", @TempDir & "WindowsXP-KB958071-x86-DEU.exe", 1)
FileInstall("WindowsXP-KB958071-x86-ENU.exe", @TempDir & "WindowsXP-KB958071-x86-ENU.exe", 1)
;############################################ Natve WiFi laden
$fDebugWifi = True
_Wlan_StartSession()
_Wlan_StartNotificationModule()
;############################################ GUI erstellen
GUICreate("WiFi Verbindung", 300, 200)
GUISetState(@SW_SHOW)
GUISetBkColor(0xF0F0F0)
GUISetFont(11)
GUICtrlCreateLabel("Bitte WLAN Passwort eingeben:", 10, 10, 200, 17)
$password = GUICtrlCreateInput("",10,40,200,20, $ES_PASSWORD)
$connect = GUICtrlCreateButton("verbinden",10,70,100,20)
$cert = GUICtrlCreateButton("Cert installieren",120,70,150,20)
$del_prof = GUICtrlCreateButton("Profil löschen",10,100,100,20)
$msKB = GUICtrlCreateButton("Hotfix Win XP",120,100,150,20)
If @OSVersion <> "WIN_XP" Then GUICtrlSetState($msKB, $GUI_DISABLE)
;############################################ Programmablauf
While 1
    Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
            Exit
  Case $connect
   If GUICtrlRead($password) = "" Then
    MsgBox(0,"Hinweis","Kein Passwort eingetragen")
    Exit
   ElseIf @OSVersion = "WIN_7" or @OSVersion = "WIN_XP" Then
    ;Disconnect() - Will do this automatically when _Wlan_Connect is called
    ;DeleteProfile() - Use _Wlan_CreateProfile() with the $fOverwrite flag)
    CreateProfile()
    SetCredentials(GUICtrlRead($password))
    _Wlan_Connect($wlan_name) ;connects to the new WLAN Profile
   Else
    ;nothing
   EndIf
  Case $Cert
   Run(@TempDir & "certmgr.exe -add " & @TempDir & "EMT-WLAN-CA.cer -s -r currentUser Root", '', @SW_HIDE)
  Case $del_prof
   DeleteProfile()
  Case $msKB
   If @OSLang = "0407" Then
    Run(@TempDir & "WindowsXP-KB958071-x86-DEU.exe")
   ElseIf @OSLang = "0409" Then
    Run(@TempDir & "WindowsXP-KB958071-x86-ENU.exe")
   Else
    MsgBox(0,"","Keine passende Sprache für Hotfix")
   EndIf
 EndSwitch
WEnd
;############################################ Funktionen
Func DeleteProfile() ;check if Profile already exists, if so delete first
 If _Wlan_DeleteProfile($wlan_name) = True Then ;IF WLAN Profile Exists Then....
  ;_Wlan_DeleteProfile($wlan_name)
  MsgBox(0,"",$wlan_name & " Profile deleted")
 Else
  MsgBox(0,"","No Profile deleted")
 EndIf
EndFunc
Func CreateProfile() ;create new WLAN Profile with Domain authentication
 Local $oProfile, $sReason
 $oProfile = _Wlan_CreateProfileObject()
 With $oProfile
  .Name = $wlan_name
  .SSID.Add($oProfile.Name)
  .Type = "Infrastructure"
  .Auth = "WPA2"
  .Encr = "AES"
  .Options.NonBroadcast = True
  .Options.ConnMode = "Automatic"
  .OneX.Enabled = True
  .OneX.AuthMode = "User"
  .PMK.PreAuthEnabled = True
  .PMK.CacheEnabled = True
  .EAP.BaseType = "PEAP"
  .EAP.Type = "PEAP-MSCHAP"
  .EAP.PEAP.MSCHAP.UseWinLogonCreds = False
 EndWith
 ;~ ConsoleWrite(_Wlan_ConvertProfile($oProfile) & @CRLF)
 ;If Not _Wlan_SetProfile($oProfile, $sReason) Then
 If Not _Wlan_SetProfile($oProfile, $sReason, 0, True) Then ;was fine as is - i'm just demonstrating the overwite flag
  MsgBox(0, "Wifi", "Failed to create profile " & $oProfile.Name & ". @error=" & @error & @CRLF & "Because: " & $sReason)
  Exit
 EndIf
EndFunc
Func SetCredentials($pw) ;Set user credentials for WLAN Profile
 $oUserData = _Wlan_CreateUserDataObject()
 With $oUserData
  .BaseType = "PEAP"
  .Type = "PEAP-MSCHAP"
  .PEAP.MSCHAP.Username = "wlanuser"
  .PEAP.MSCHAP.Password = "" & $pw & ""
  .PEAP.MSCHAP.Domain = "lcldom"
 EndWith
 ;ConsoleWrite(_Wlan_ConvertUserData($oUserData) & @CRLF)
 ;_Wlan_SetProfileUserData($wlan_name, $oUserData, 1) the all users flag can only be used in win7 ( I don't think it works anyway - bug in windows :( )
 _Wlan_SetProfileUserData($wlan_name, $oUserData, 0)
EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0