Platform SDK: Windows Networking |
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 WNetCancelConnection2( LPCTSTR lpName, // resource name DWORD dwFlags, // connection type BOOL fForce // unconditional disconnect option );
If this parameter specifies a redirected local resource, the function cancels only the specified redirection; otherwise, the function cancels all connections to the remote network resource.
Value | Meaning |
---|---|
0 | The system does not update information about the connection.
If the connection was marked as persistent in the registry, the system continues to restore the connection at the next logon. If the connection was not marked as persistent, the function ignores the setting of the CONNECT_UPDATE_PROFILE flag. |
CONNECT_UPDATE_PROFILE | The system updates the user profile with the information that the connection is no longer a persistent one.
The system will not restore this connection during subsequent logon operations. (Disconnecting resources using remote names has no effect on persistent connections.) |
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value can be one of the following error codes.
Value | Meaning |
---|---|
ERROR_BAD_PROFILE | The user profile is in an incorrect format. |
ERROR_CANNOT_OPEN_PROFILE | The system is unable to open the user profile to process persistent connections. |
ERROR_DEVICE_IN_USE | The device is in use by an active process and cannot be disconnected. |
ERROR_EXTENDED_ERROR | A network-specific error occurred. To obtain a description of the error, call the WNetGetLastError function. |
ERROR_NOT_CONNECTED | 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. |
ERROR_OPEN_FILES | There are open files, and the fForce parameter is FALSE. |
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.
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in Winnetwk.h.
Library: Use Mpr.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.
Windows Networking (WNet) Overview, Windows Networking Functions, WNetAddConnection2, WNetAddConnection3, WNetGetConnection