DWORD CMyDlg::FindServer (const CString& rcsTarget, BOOL& bFound) { NET_API_STATUS nas ; NET_DISPLAY_MACHINE * pndm; SERVER_INFO_101 * pSI_101 ; DWORD dwEntriesRead; DWORD dwTotalEntries; DWORD dwRetVal = ERROR_SUCCESS; DWORD dwNdmCount; int iCount; long lScratch; char szServer [64]; char szDebug [256]; WCHAR wcServer [64]; CString csServer; CString csTarget = rcsTarget; bFound = FALSE; nas = NetServerEnum (NULL,  101, (LPBYTE*)&pSI_101, MAX_PREFERRED_LENGTH, &dwEntriesRead, &dwTotalEntries, SV_TYPE_SERVER, // type you're looking for. NULL, 0); if (nas == NERR_Success) { wsprintf (szDebug, "NetServerEnum found %u server(s)\n", dwEntriesRead); OutputDebugString (m_szDebug); if (dwEntriesRead) { for (iCount=0; iCount<(int)dwEntriesRead; iCount++) { if (pSI_101[iCount].sv101_name == NULL || IsBadReadPtr (pSI_101[iCount].sv101_name, sizeof(WCHAR))) { wsprintf (szDebug, "server name ptr 0x%08X is unusable\n",  pSI_101[iCount].sv101_name); OutputDebugString (m_szDebug); } else { if (WideCharToMultiByte (CP_ACP, WC_COMPOSITECHECK, (LPCWSTR)(pSI_101[iCount].sv101_name), -1, szServer, sizeof(szServer), NULL, NULL) == 0) { dwRetVal = GetLastError (); wsprintf (szDebug, "WCTMB gave error %u\n", dwRetVal); OutputDebugString (m_szDebug); } else { csServer = szServer; wsprintf (szDebug, "server '%s' found\n", szServer); OutputDebugString (m_szDebug); csServer.MakeUpper(); csTarget.MakeUpper(); if (csServer == csTarget) { OutputDebugString ("Server matches target, try to access it\n"); // The browse info will continue to report machines // for ages after they've been switched off, so try to // talk direct to the machine. wcscpy (wcServer, L"\\\\"); wcscat (wcServer, (LPCWSTR)(pSI_101[iCount].sv101_name)); nas = NetQueryDisplayInformation (wcServer, 2, 0, 1, sizeof(NET_DISPLAY_MACHINE), &dwNdmCount, (PVOID*)&pndm); switch (nas) { case NERR_Success: case ERROR_MORE_DATA: OutputDebugString ("NQDI successful\n"); bFound = TRUE; break; default: wsprintf (szDebug, "NQDI gave error %u\n", nas); OutputDebugString (m_szDebug); dwRetVal = nas; break; } NetApiBufferFree ((PVOID)pndm); if (bFound) break; } } } } } NetApiBufferFree (pSI_101); } else { wsprintf (szDebug, "NetServerEnum gave error %u\n", nas); OutputDebugString (m_szDebug); dwRetVal = nas; } return (dwRetVal); }