Jump to content

Connect to a WiFi SSID


Recommended Posts

Hi,

Is there any example code that shows how to auto connect to a WEP wireless network.

if it possible no GUI!!!

after searching and founding my network i want automatically connect to this network.

Thanks,

Ziv

Link to comment
Share on other sites

Calling to _Wlan_Connect retuerns error (@error) 2.

from MSDN - "The system cannot find the file specified."

!APIError @Ln[2182] _WinAPI_WlanConnect - The parameter is incorrect.

Any idea?

Thanks,

Ziv

Link to comment
Share on other sites

hey man,

Just to clarify things:

An @error value of 2 only indicates the function failed because of an API error - nothing more. The actual API error code lives in @extended - this case it will be 87 (The parameter is incorrect.)

As far as notifications go, XP uses them horribly. You've probably found the only codes it supports are $WLAN_NOTIFICATION_ACM_CONNECTION_COMPLETE and $WLAN_NOTIFICATION_ACM_DISCONNECTED. This is all well and good - except in XP "connection complete" does not always men the connection is complete.

After calling the connect function the "connection complete" notification will appear three times. First time it will mean "the connection has started", second time associated (i assume), and finally connected. Of course if a disconnected notification appears in the middle somewhere the next connected notification will mean "the connection has started"... It is also worth noting the disconnected notification also appears a few times when disconnecting.

If you don't want to deal with all that mess - just use the wait flag when calling _Wlan_Connect() and let the UDF deal with it.

#include "NativeWifi.au3"

$fDebugWifi = True

_Wlan_StartSession()
_Wlan_StartNotificationModule()

Local $oProfile, $sReason

$oProfile = _Wlan_CreateProfileObject()
With $oProfile
.Name = "Test"
.SSID.Add($oProfile.Name)
.Type = "Infrastructure"
.Auth = "Shared Key"
.Encr = "WEP"
.Key.Protected = False
.Key.Type = "Network Key"
.Key.Material = "MyKey"
EndWith

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

Hope this helps,

Matt

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...