WlanDisconnect function (wlanapi.h)

The WlanDisconnect function disconnects an interface from its current network.

Syntax

DWORD WlanDisconnect(
  [in] HANDLE     hClientHandle,
  [in] const GUID *pInterfaceGuid,
       PVOID      pReserved
);

Parameters

[in] hClientHandle

The client's session handle, obtained by a previous call to the WlanOpenHandle function.

[in] pInterfaceGuid

The GUID of the interface to be disconnected.

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
ERROR_INVALID_PARAMETER
hClientHandle is NULL or invalid, pInterfaceGuid is NULL, or pReserved is not NULL.
ERROR_INVALID_HANDLE
The handle hClientHandle was not found in the handle table.
RPC_STATUS
Various error codes.
ERROR_NOT_ENOUGH_MEMORY
Failed to allocate memory for the query results.
ERROR_ACCESS_DENIED
The caller does not have sufficient permissions.

Remarks

When the connection was established using WlanConnect, a profile was specified by the strProfile member of the WLAN_CONNECTION_PARAMETERS structure pointed to by pConnectionParameters. If that profile was an all-user profile, the WlanDisconnect caller must have execute access on the profile. Otherwise, the WlanDisconnect 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 disconnection operation at the command line, use the netsh wlan disconnect 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:  WlanDisconnect has the side effect of modifying the profile associated with the disconnected network. A network profile becomes an on-demand profile after a WlanDisconnect call. The Wireless Zero Configuration service will not connect automatically to a network with an on-demand profile when the network is in range. Do not call WlanDisconnect before calling WlanConnect unless you want to change a profile to an on-demand profile. When you call WlanConnect to establish a network connection, any existing network connection is dropped automatically.

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

See also

WlanConnect