Windows NT Only
To cancel a connection to a network resource, an application can call the WNetCancelConnection2 function, as shown in the following example.
DWORD dwResult;
dwResult = WNetCancelConnection2("z:",
CONNECT_UPDATE_PROFILE, // remove connection from profile
FALSE); //fail if open files or jobs
if (dwResult == ERROR_NOT_CONNECTED)
{
TextOut(hdc, 10, 10, "Drive z: not connected.", 23);
return FALSE;
}
else if(dwResult != NO_ERROR)
{
// An application-defined error handler is demonstrated in the
// section titled "Retrieving Network Errors."
NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetCancelConnection2");
return FALSE;
}
TextOut(hdc, 10, 10, "Connection closed for z:.", 25);
The WNetCancelConnection function is supported for compatibility with earlier versions of Windows for Workgroups. For new applications, use WNetCancelConnection2.