This function breaks an existing network connection. It may also be used to remove a persistent connection for which there is no existing network connection.
When WNetCancelConnection2 is called it removes the connection entirely if it is to a redirected local device or a non-reference counted session, or if CONNECT_REFCOUNT bit is not set in the dwFlags parameter. Otherwise WNetCancelConnection2 decrements the reference count to the session and removes the session when it is no longer being referenced.
DWORD WNetCancelConnection2(
LPTSTR lpName,
DWORD dwFlags,
BOOL fForce
);
CONNECT_UPDATE_PROFILE | If the disconnection should remain persistent. If set, Windows will no longer restore this connection when the user logs on. |
CONNECT_REFCOUNT | If this bit is not set, the connection is to a redirected local device, or the connection is not reference counted, then the connection is cancelled completely (which will interfere with other threads or processes that are using the connection). If this bit is set and the connection supports reference counts then the reference count to the connection is descremented. When nothing is referencing the connection it is cancelled. |
WN_NOT_CONNECTED | lpName not a redirected or persistent device, or not currently connected to lpName. |
WN_CANNOT_OPEN_PROFILE | Unable to open the user profile to process persistent connections. |
WN_DEVICE_IN_USE | The device is in use by an active process and cannot be disconnected. |
WN_BAD_PROFILE | The user profile is in an incorrect format. |
WN_OPEN_FILES | there are open files and fForce was FALSE. |
WN_FUNCTION_BUSY | The MPR or NP is busy (possibly initializing). The caller should retry. |
WN_EXTENDED_ERROR | a network specific error occurred. WNetGetLastError should be called to obtain a description of the error. |