WNetCancelConnection

This function breaks an existing network connection. This function is equivalent to WNetCancelConnection2 with CONNECT_UPDATE_PROFILE set for dwFlags, i.e., the list of persistent connections will be updated so that Windows will no longer restore this connection.

DWORD WNetCancelConnection(
    LPTSTR lpName,
    BOOL fForce
    );
 
lpName
The name of either the redirected local device or the remote network resource to disconnect from. In the former case, only the redirection specified is broken, in the latter case only the deviceless connection to the remote network resource is broken.
fForce
Used to indicate if the disconnect should be done forcefully in the event of open files or jobs on the connection. If FALSE is specified, the call will fail if there are open files or jobs.
WN_NOT_CONNECTED lpName not a redirected (nor 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.