WlanConnect function (wlanapi.h)
The WlanConnect function attempts to connect to a specific network.
Syntax
DWORD WlanConnect(
[in] HANDLE hClientHandle,
[in] const GUID *pInterfaceGuid,
[in] const PWLAN_CONNECTION_PARAMETERS pConnectionParameters,
PVOID pReserved
);
Parameters
[in] hClientHandle
The client's session handle, returned by a previous call to the WlanOpenHandle function.
[in] pInterfaceGuid
The GUID of the interface to use for the connection.
[in] pConnectionParameters
Pointer to a WLAN_CONNECTION_PARAMETERS structure that specifies the connection type, mode, network profile, SSID that identifies the network, and other parameters.
Windows XP with SP3 and Wireless LAN API for Windows XP with SP2: There are some constraints on the WLAN_CONNECTION_PARAMETERS members. This means that structures that are valid for Windows Server 2008 and Windows Vista may not be valid for Windows XP with SP3 or Wireless LAN API for Windows XP with SP2. For a list of constraints, see WLAN_CONNECTION_PARAMETERS.
pReserved
Reserved for future use. Must be set to NULL.
Return value
If the function succeeds, the return value is ERROR_SUCCESS.
If the function fails, the return value may be one of the following return codes.
Return code | Description |
---|---|
|
One of the following conditions occurred:
|
|
The handle hClientHandle was not found in the handle table. |
|
Various error codes. |
|
The caller does not have sufficient permissions. |
Remarks
The WlanConnect function returns immediately. To be notified when a connection is established or when no further connections will be attempted, a client must register for notifications by calling WlanRegisterNotification.
The strProfile member of the WLAN_CONNECTION_PARAMETERS structure pointed to by pConnectionParameters specifies the profile to use for connection. If this profile is an all-user profile, the WlanConnect caller must have execute access on the profile. Otherwise, the WlanConnect call will fail with return value ERROR_ACCESS_DENIED. The permissions on an all-user profile are established when the profile is created or saved using WlanSetProfile or WlanSaveTemporaryProfile.
To perform a connection operation at the command line, use the netsh wlan connect command. For more information, see Netsh Commands for Wireless Local Area Network (wlan).
Windows XP with SP3 and Wireless LAN API for Windows XP with SP2: You can only use WlanConnect to connect to networks on the preferred network list. To add a network to the preferred network list, call WlanSetProfile.
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows Vista, Windows XP with SP3 [desktop apps only] |
Minimum supported server | Windows Server 2008 [desktop apps only] |
Target Platform | Windows |
Header | wlanapi.h (include Wlanapi.h) |
Library | Wlanapi.lib |
DLL | Wlanapi.dll |
Redistributable | Wireless LAN API for Windows XP with SP2 |