Extracting shared drive information from a local or remote server

Environment: VC6 SP3, NT4 SP5

To extract shared drive information from a local or remote server (including shared and system shared drives), implement the following code into your sources.



int CNetworkAccess::EnumerateResource (LPSTR svrname)
{
	PSHARE_INFO_502 BufPtr, p;
	NET_API_STATUS res;
	DWORD er = 0, tr = 0, resume = 0;
	WCHAR serverName[36];
	int ierror = 0;

	// convert to a unicode string
	if ((ierror = MultiByteToWideChar (CP_ACP,
					   MB_PRECOMPOSED,
					   svrname,
					   -1,
					   serverName,
					   36)) == 0)
	{
		AfxMessageBox ("BAD conversion -> bugging out ... !!!");
		return STATUS_BAD;
	}

	do
	{
		// return shared drive information for the server selected
		res = NetShareEnum ((TCHAR *)serverName,
				    502,
				    (LPBYTE *)&BufPtr,
				    0xFFFFFFFF,
				    &er,
				    &tr,
				    &resume);

		// if OK
		if (res == ERROR_SUCCESS || res == ERROR_MORE_DATA)
		{
			p = BufPtr;
			for (int i = 1; i <= (int)er; i++)
			{
				// do something with the drive information
				
				// increment pointer to next drive
				p++;
			}
			// free system created memory
			NetApiBufferFree (BufPtr);
		}

	} while (res == ERROR_MORE_DATA);

	// return the status
	return STATUS_OK;
}

To extract information from the local server, pass NULL into the function

History