dcsimg

Extracting shared drive information from a local or remote server

WEBINAR:
On-Demand

Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame


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



Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date