Platform SDK: Windows Networking

WNetCancelConnection

The WNetCancelConnection function cancels an existing network connection.

The WNetCancelConnection function is provided for compatibility with 16-bit versions of Windows. Win32-based applications should call the WNetCancelConnection2 function.

DWORD WNetCancelConnection(
  LPCTSTR lpName,  // resource name
  BOOL fForce      // unconditional disconnect option
);

Parameters

lpName
[in] 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.

When this parameter specifies a redirected local device, the function cancels only the specified device redirection. If the parameter specifies a remote network resource, only the connections to remote networks without devices are canceled.

fForce
[in] Specifies whether or not 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.

Return Values

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.

Requirements

  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.

See Also

Windows Networking (WNet) Overview, Windows Networking Functions, WNetAddConnection, WNetAddConnection2, WNetCancelConnection2, WNetGetConnection