Extracting shared drive information from a local or remote server | CodeGuru

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; […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 2, 1999
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.