WNetCancelConnection2

  DWORD WNetCancelConnection2(lpszName, fdwConnection, fForce)    
  LPTSTR lpszName; /* pointer to resource name to disconnect */
  DWORD fdwConnection; /* connection-type flags */
  BOOL fForce; /* flag for forcing disconnect */

The WNetCancelConnection2 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 resource, only the specified redirection is broken; otherwise, all connections to the remote network resource are broken.

fdwConnection

Specifies a bitmask for the connection type. The following values are defined:

Value Meaning

0  
  No information about the connection is stored.
CONNECT_UPDATE_PROFILE  
  The user profile is updated with the information that this is no longer a persistent connection. Windows will not restore this connection during subsequent log-on operations. Disconnecting resources using remote names has no impact on persistent connections.

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. If the return value is not NO_ERROR, the GetLastError function should be used to determine the cause of the failure. Possible return values from GetLastError include:

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.

See Also

WNetAddConnection2, WNetCancelConnection, WNetGetConnection