The WNetCancelConnection2 function cancels an existing network connection. You can also call the function to remove remembered network connections that are not currently connected.
The WNetCancelConnection2 function supersedes the WNetCancelConnection function.
DWORD WNetCancelConnection2A( LPCSTR lpName, DWORD dwFlags, BOOL fForce );
Pointer to a constant null-terminated string that specifies the name of either the redirected local device or the remote network resource to disconnect from.
If this parameter specifies a redirected local device, the function cancels only the specified device redirection. If the parameter specifies a remote network resource, all connections without devices are canceled.
Connection type. The following values are defined.
Specifies whether the disconnection should occur if there are open files or jobs on the connection. If this parameter is FALSE, the function fails if there are open files or jobs.
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is a system error code, such as one of the following values.
||The user profile is in an incorrect format.|
||The system is unable to open the user profile to process persistent connections.|
||The device is in use by an active process and cannot be disconnected.|
||A network-specific error occurred. To obtain a description of the error, call the WNetGetLastError function.|
||The name specified by the lpName parameter is not a redirected device, or the system is not currently connected to the device specified by the parameter.|
||There are open files, and the fForce parameter is FALSE.|
Windows Server 2003 and Windows XP: The WNet functions create and delete network drive letters in the MS-DOS device namespace associated with a logon session because MS-DOS devices are identified by AuthenticationID. (An AuthenticationID is the locally unique identifier, or LUID, associated with a logon session.) This can affect applications that call one of the WNet functions to create a network drive letter under one user logon, but query for existing network drive letters under a different user logon. An example of this situation could be when a user's second logon is created within a logon session, for example, by calling the CreateProcessAsUser function, and the second logon runs an application that calls the GetLogicalDrives function. GetLogicalDrives does not return network drive letters created by a WNet function under the first logon. Note that in the preceding example the first logon session still exists, and the example could apply to any logon session, including a Terminal Services session. For more information, see Defining an MS-DOS Device Name.
For a code sample that illustrates how to cancel a connection to a network resource with a call to the WNetCancelConnection2 function, see Canceling a Network Connection.
|Minimum supported client||Windows 2000 Professional [desktop apps only]|
|Minimum supported server||Windows 2000 Server [desktop apps only]|