+ Reply to Thread
Results 1 to 2 of 2

Thread: Enumerate network resources under windows machine

  1. #1

    Enumerate network resources under windows machine

    How can I enumerate network resources on my windows based machine? I would like to do it in C/C++/.Net application. Please provide me some ideas.
    Thanks in advance.

  2. #2
    Code:
    void EnumNetworkResources(NETRESOURCE* pNetworkResource)
    {
    	HANDLE hEnumerator = NULL ;
    	DWORD dwError = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, RESOURCEUSAGE_ALL, pNetworkResource, &hEnumerator) ;
    	if (dwError == NO_ERROR)
    	{
    		DWORD			dwCount = -1 ;
    		LPNETRESOURCE	lpNetworkResource = NULL ;
    		DWORD			dwBufferLength = 16384 ;
    		lpNetworkResource = (LPNETRESOURCE) GlobalAlloc(GPTR, dwBufferLength) ;
    		if (lpNetworkResource != NULL)
    		{
    			do
    			{
    				ZeroMemory(lpNetworkResource, dwBufferLength) ;
    				
    				dwError = WNetEnumResource(hEnumerator, &dwCount, lpNetworkResource, &dwBufferLength);
    				if (dwError == NO_ERROR)
    				{
    					for (int nIndex = 0; nIndex < dwCount; nIndex++)
    					{
    						if (RESOURCEUSAGE_CONTAINER == (lpNetworkResource[nIndex].dwUsage & RESOURCEUSAGE_CONTAINER))
    						{
    							EnumNetworkResources(&lpNetworkResource[nIndex]) ;
    						}
    					}
    				}
    				else if (dwError != ERROR_NO_MORE_ITEMS)
    				{
    					break ;
    				}
    			}
    			while (dwError != ERROR_NO_MORE_ITEMS);
    
    			GlobalFree((HGLOBAL) lpNetworkResource) ;
    		}
    
    		WNetCloseEnum(hEnumerator) ;
    	}
    }
    Use above approach to enumerate network resources.

    Note:
    a. It is recursive function.
    b. It enumerates all the network resources.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts