enum domain & computers in a network
hello again,
i refered your suggession and created one MFC application ....in which i m creating a button , a combo box a list box and some other control for my project.
1. what i did (achieved) is :
when i clicked the button the application is flooding the no of domains ,servers and the individual computers at a time in a sequence by a callback function NetServerEnum() (callback --->i think so till now not checked) & i m displaying in the list box. but my requirement is different in the following manner ....
2. my requirement is :
when i click the button the application should enumerate the no of domains first and should put in the combo box.then when i will select one of the domain from the combo , i should get the list of computers in that particular domain , which i want to show in the list box.
how to do that ... using the same function ...??
please guide me ...
thanking u.
panda
Re: enum domain & computers in a network
Hi,
my program using NetServerEnum is not getting all of the workstations on the network the MSDN states:
ERROR_MORE_DATA More entries are available. Specify a large enough buffer to receive all entries.
So how do I specify a large enough buffer to get all the workstations??
Code:
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_WORKSTATION; // all workstations
DWORD dwResumeHandle = 0;
NET_API_STATUS nStatus;
LPCWSTR pszServerName = NULL;
LPCWSTR domain = (LPCWSTR)m_strDom.GetBuffer();
DWORD i;
// Call the NetServerEnum function to retrieve information
// for all workstations, specifying information level 101.
//
nStatus = NetServerEnum(pszServerName,
dwLevel,
(LPBYTE *) &pBuf,
dwPrefMaxLen,
&dwEntriesRead,
&dwTotalEntries,
dwServerType,
domain,
&dwResumeHandle);
//
// If the call succeeds,
//
if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
{
if ((pTmpBuf = pBuf) != NULL)
{
//
// Loop through the entries and
// print the data for all server types.
//
for (i = 0; i < dwEntriesRead; i++)
{
ASSERT(pTmpBuf != NULL);
if (pTmpBuf == NULL)
{
break;
}
CString n = pTmpBuf->sv101_name;
GetListCtrl().InsertItem(i,n);
pTmpBuf++;
dwTotalCount++;
}
}
}
// Free the allocated buffer.
if (pBuf != NULL)
NetApiBufferFree(pBuf);
Re: enum domain & computers in a network
Well, in MSDN is stated that If you specify MAX_PREFERRED_LENGTH, the function allocates the amount of memory required for the data. Still returns ERROR_MORE_DATA?
Re: enum domain & computers in a network
Hi ovidiucucu, thanks for replying,
with max_preferred_length set it NEVER returns ERROR_MORE_DATA.
it only returns ERROR_MORE_DATA if I change the value to greater than or less than max_preferred_length
either netserverenum is failing to return all workstations OR it only lists those workstations with someone logged onto them
In other words, it's not like reading the active directory which will return every workstation.
I found an undocumented function NetServerEnumEx which is supposed to return more workstations (the resume variable is not reserved in this function) but I couldn't get it to work. It kept reporting Linker errors, but I don't know why, NetServerEnumEx is in the same file as NetServerEnum!
And since it's undocumented, I don't know what additional libraries or files to include to make it work!!