HOWTO: Enumerate MSCS Clusters in a Domain

ID: Q217203


The information in this article applies to:


SUMMARY

This article provides sample code that demonstrates enumerating all Microsoft Cluster Server (MSCS) Clusters in a domain.


MORE INFORMATION

There is a reserved bit for clusters in the NetBios information for a server. The bit is set only if the server name is a Cluster Name resource. This does not apply to virtual server names. There is no direct way to enumerate virtual servers in a domain or to determine whether or not a given server is virtual. By calling NetServerEnum with the SV_TYPE_CLUSTER_NT flag, a list of all clusters in the specified domain is returned:

  1. In Microsoft Visual C++ 6.0, create a new Win32 Console Application. Choose An Empty Project on the dialog box that appears, and click Finish.


  2. From the Project menu, choose Settings.


  3. Click the Link tab of the Settings dialog box that appears.


  4. Add Clusapi.lib and Netapi32.lib to the list of .lib files in the Object/library Modules text box.


  5. Add a new C source file to the project.


  6. Add the following code to the source file:
    
    #include <windows.h>
    #include <clusapi.h>
    #include <lmcons.h>
    #include <lmserver.h>
    #include <lmapibuf.h>
    #include <stdio.h>
    
    int main(int argc, char* argv[])
    {
    
    	// Collect list of clusters from the network.
    	DWORD	dwStatus;
    	DWORD	nEntriesRead;
    	DWORD	nTotalEntries;
    	DWORD	iEntry;
    	SERVER_INFO_100 * pServerInfo = NULL;
    	SERVER_INFO_100 * pCurServerInfo;
    
    	dwStatus = NetServerEnum(
    		NULL,				// servername
    		100,				// level
    		(LPBYTE *) &pServerInfo,
    		4096,				// prefmaxlen
    		&nEntriesRead,			// entriesread
    		&nTotalEntries,			// totalentries
    		SV_TYPE_CLUSTER_NT,		// servertype
    		NULL,				// domain
    		NULL				// resume_handle
    		);
    
    
    	if( ERROR_SUCCESS == dwStatus && NULL != pServerInfo ){
    	
    		wprintf( L"Clusters found in the domain: \n" );
    	
    		pCurServerInfo = pServerInfo;
    
    		for (iEntry = 0 ; iEntry < nTotalEntries ; iEntry++, pCurServerInfo++){
    			wprintf( L"%s\n", pCurServerInfo->sv100_name );
    		}  
    	
    		NetApiBufferFree(pServerInfo);	
    	
    	}  
    	else{
    		wprintf( L"No clusters were found in the domain.\n" );
    	}
    			
    	return 0;	
    } 


  7. Compile the project.


  8. Run the project.


RESULT: The application will list all Cluster Servers on the current Windows NT domain.

Additional query words:


Keywords          : kbClustServ kbClustServ100 kbGrpPlatform kbDSupport 
Version           : winnt:4.0
Platform          : winnt 
Issue type        : kbhowto 

Last Reviewed: July 23, 1999