WNetCancelConnection

  DWORD WNetCancelConnection(lpszName, fForce)    
  LPTSTR lpszName; /* pointer to resource name to disconnect */
  BOOL fForce; /* flag for forcing disconnect */

The WNetCancelConnection function breaks an existing network connection.

Parameters

lpszName

Points to a null-terminated string that specifies the name of either the redirected local device or the remote network resource to disconnect from. If lpszName specifies a redirected local device, only the specified redirection is broken, and a persistent connection will no longer be persistent. (That is, Windows will not restore the connection during subsequent log-on operations.) If lpszName specifies a remote network resource, all connections to the remote network resource are broken, and any persistent connections remain persistent.

fForce

Specifies whether the disconnection should occur even if there are open files or jobs on the connection. If fForce is FALSE, the function fails if there are open files or jobs.

Return Value

If the function is successful, the return value is NO_ERROR. Otherwise, it is an error code, which may be one of the following:

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. Use the WNetGetLastError function to obtain a description of the error.
ERROR_NOT_CONNECTED The name specified by lpszName is not a redirected device, or the system is not currently connected to lpszName.
ERROR_OPEN_FILES There are open files and the fForce parameter was FALSE.

This function returns error codes for compatibility with Windows 3.1. For compatibility with Win32, the function also sets the error-code value returned by the GetLastError function.

See Also

WNetAddConnection, WNetCancelConnection2, WNetGetConnection