First of all, You might use the function below to get a list of computer name,
then you can store this list to a file or database, and develop a service to maintain
it at intervals, other computers will access this file or database to get this list.
BOOL WINAPI EnumerateFunc(HWND hwnd,
HDC hdc,
LPNETRESOURCE lpnr)
{
DWORD dwResult, dwResultEnum;
HANDLE hEnum;
DWORD cbBuffer = 16384; // 16K is a good size
DWORD cEntries = 0xFFFFFFFF; // enumerate all possible entries
LPNETRESOURCE lpnrLocal; // pointer to enumerated structures
DWORD i;
dwResult = WNetOpenEnum(RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
0, // enumerate all resources
lpnr, // NULL first time this function is called
&hEnum); // handle to resource
if (dwResult != NO_ERROR) {
// An application-defined error handler is demonstrated in the
// section titled "Retrieving Network Errors."
NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetOpenEnum");
return FALSE;
}
do {
// Allocate memory for NETRESOURCE structures.
lpnrLocal = (LPNETRESOURCE) GlobalAlloc(GPTR, cbBuffer);
dwResultEnum = WNetEnumResource(hEnum, // resource handle
&cEntries, // defined locally as 0xFFFFFFFF
lpnrLocal, // LPNETRESOURCE
&cbBuffer); // buffer size
if (dwResultEnum == NO_ERROR) {
for(i = 0; i < cEntries; i++)
{
// Following is an application-defined function for
// displaying contents of NETRESOURCE structures.
DisplayStruct(hdc, &lpnrLocal);
//
// If this NETRESOURCE is a container, call the function
// recursively.
if(RESOURCEUSAGE_CONTAINER ==
(lpnrLocal.dwUsage & RESOURCEUSAGE_CONTAINER))
if(!EnumerateFunc(hwnd, hdc, &lpnrLocal))
TextOut(hdc, 10, 10,
"EnumerateFunc returned FALSE.", 29);
}
}
else if (dwResultEnum != ERROR_NO_MORE_ITEMS) {
NetErrorHandler(hwnd, dwResultEnum, (LPSTR)"WNetEnumResource");
break;
}
}
while(dwResultEnum != ERROR_NO_MORE_ITEMS);
GlobalFree((HGLOBAL) lpnrLocal);
dwResult = WNetCloseEnum(hEnum);
if(dwResult != NO_ERROR) {
NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetCloseEnum");
return FALSE;
}
return TRUE;
}