@bobnoordam

Connecting a network drive using the win32 api

// Connect network drive (local, remote)
void connect(_TCHAR* localName, _TCHAR* remoteName)
{
    NETRESOURCE netResource;
	DWORD dwFlags;
	DWORD dwRetVal;
	// clear & construct netresource struct
	memset(&netResource, 0, sizeof (NETRESOURCE));
	netResource.dwType = RESOURCETYPE_ANY;
	netResource.lpLocalName = localName;
	netResource.lpRemoteName = remoteName;
	netResource.lpProvider = NULL;
	dwFlags = CONNECT_UPDATE_PROFILE; // persist connection
	dwRetVal = WNetAddConnection2(&netResource, NULL, NULL, dwFlags); // connect
	if (dwRetVal == NO_ERROR)
		wprintf(L"Connection added %s\n", netResource.lpRemoteName);
	else
		wprintf(L"Connection failed for %s with error: %u\n",localName, dwRetVal);
}