How to get all the system names in the LAN .. may be inside an office using VC++ MFC. Dialog Based application and how to list the names in the list control...Pls Help Me.. :(
Modification [OP's anwswer]:
I found the solution myself.
m_ListCtrl->InsertColumn(0,_T("Name"),0,130);
LPSERVER_INFO_101 pBuf = NULL;
LPSERVER_INFO_101 pTmpBuf;
DWORD dwLevel = 101;
DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
DWORD dwEntriesRead = 0;
DWORD dwTotalEntries = 0;
DWORD dwTotalCount = 0;
DWORD dwServerType = SV_TYPE_ALL; DWORD dwResumeHandle = 0;
NET_API_STATUS nStatus;
wchar_t *pszServerName = NULL;
DWORD i; pszServerName = L"\\\\cgdomain.com"; nStatus = NetServerEnum(pszServerName,dwLevel,(LPBYTE *) &pBuf,dwPrefMaxLen,&dwEntriesRead,&dwTotalEntries,dwServerType,NULL,&dwResumeHandle);
if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
{
if ((pTmpBuf = pBuf) != NULL)
{
for (i = 0; i < dwEntriesRead; i++)
{
if (pTmpBuf == NULL)
{
break;
}
char szTxt[MAX_PATH]={0};
::WideCharToMultiByte( CP_ACP, 0,pTmpBuf->sv101_name,-1, szTxt,MAX_PATH, NULL, 0);
CString strValue,strTemp1,strTemp2;
strValue=szTxt;
strTemp1=strValue.GetAt(0);
strTemp2=strValue;
strTemp2.Delete(0);
strTemp2.MakeLower();
strValue="";
strValue=strTemp1+strTemp2;
m_ListCtrl->InsertItem(i,strValue);
pTmpBuf++;
dwTotalCount++;
}
}
}
else
AfxMessageBox(_T("A system error has occurred"));
if (pBuf != NULL)
NetApiBufferFree(pBuf);