To make a connection to a network resource described by a NETRESOURCE structure, an application can call the WNetAddConnection2 function, as shown in the following code fragment:
DWORD dwResult;
NETRESOURCE nr;
dwResult = WNetAddConnection2(&nr, /* NETRESOURCE from enumeration */
(LPSTR) NULL, /* no password */
(LPSTR) NULL, /* use standard user name */
CONNECT_UPDATE_PROFILE); /* update profile with connect info */
if (dwResult == ERROR_ALREADY_ASSIGNED) {
TextOut(hdc, 10, 10, "Already connected to specified resource.", 40);
return FALSE;
}
else if (dwResult == ERROR_DEVICE_ALREADY_REMEMBERED) {
TextOut(hdc, 10, 10,
"Attempted reassignment of remembered device.", 44);
return FALSE;
}
else if(dwResult != NO_ERROR) {
ErrorHandler(hwnd, dwResult, "WNetAddConnection2");
return FALSE;
}
TextOut(hdc, 10, 10, "Connected to specified resource.", 32);
return TRUE;
The WNetAddConnection function is supported for compatibility with earlier versions of Windows. New applications should use WNetAddConnection2.