NetShareGetInfo() Program Example
This function retrieves information about a particular shared resource on a server. The following code sample demonstrates how to retrieve information about a particular shared resource using a call to the NetShareGetInfo() function. The sample calls NetShareGetInfo(), specifying information level 502 (SHARE_INFO_502). If the call succeeds, the code prints the retrieved data. The sample also calls the IsValidSecurityDescriptor() function to validate the shi502_security_descriptor member. Finally, the sample frees the memory allocated for the information buffer.
Create a new empty Win32 console application project. Give the project name and change the project location is needed.

Then, add the source file and give it a suitable name.

Then, add the following source code.
#include <windows.h>
#include <stdio.h>
#include <lm.h>
#pragma comment(lib, Netapi32.lib)
int wmain(int argc, WCHAR *lpszArgv[])
{
PSHARE_INFO_502 BufPtr;
NET_API_STATUS res;
LPTSTR lpszServer = NULL, lpszShare;
// Check command line arguments.
switch(argc)
{
case 3:
lpszServer = lpszArgv[2];
case 2:
lpszShare = lpszArgv[1];
break;
default:
{
wprintf(LUsage: %s sharename <servername>\n, lpszArgv[0]);
wprintf(LExample: %s testsharefolder Bigserver\n, lpszArgv[0]);
return 1;
}
}
// Call the NetShareGetInfo() function, specifying level 502.
if((res = NetShareGetInfo(lpszServer,lpszShare,502,(LPBYTE *) &BufPtr)) == ERROR_SUCCESS)
{
wprintf(LNetShareGetInfo() is OK!\n\n);
// Print the retrieved data.
wprintf(LShare name Path Current Use\n);
wprintf(L----------------------------------\n);
wprintf(L%s\t%s\t%u\n\n,BufPtr->shi502_netname, BufPtr->shi502_path, BufPtr->shi502_current_uses);
// Validate the value of the shi502_security_descriptor member.
if (IsValidSecurityDescriptor(BufPtr->shi502_security_descriptor))
wprintf(LIt has a valid Security Descriptor.\n);
else
wprintf(LIt does not have a valid Security Descriptor.\n);
// Free the allocated memory.
NetApiBufferFree(BufPtr);
}
else
{
wprintf(LNetShareGetInfo() failed, error: %ld\n, res);
}
return 0;
}
Build and run the project. The following screenshot is a sample output based on the previous shared folder.

