16.2.6 Canceling a Network Connection

To cancel a connection to a network resource, an application can call the WNetCancelConnection2 function, as shown in the following code fragment:

DWORD dwResult;

dwResult = WNetCancelConnection2("z:",

CONNECT_UPDATE_PROFILE, /* remove connection from profile */

FALSE); /* fail if there are 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) {

ErrorHandler(hwnd, dwResult, "WNetCancelConnection2");

return FALSE;

}

TextOut(hdc, 10, 10, "Connection closed for z:.", 25);

The WNetCancelConnection function is supported for compatibility with earlier versions of Windows. New applications should use WNetCancelConnection2.