This topic has not yet been rated - Rate this topic

NetShareGetInfo function

Applies to: desktop apps only

Retrieves information about a particular shared resource on a server.

Syntax

NET_API_STATUS NetShareGetInfo(
  __in   LPWSTR servername,
  __in   LPWSTR netname,
  __in   DWORD level,
  __out  LPBYTE *bufptr
);

Parameters

servername [in]

Pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this parameter is NULL, the local computer is used.

netname [in]

Pointer to a string that specifies the name of the share for which to return information.

level [in]

Specifies the information level of the data. This parameter can be one of the following values.

ValueMeaning
0

Return the share name. The bufptr parameter points to a SHARE_INFO_0 structure.

1

Return information about the shared resource, including the name and type of the resource, and a comment associated with the resource. The bufptr parameter points to a SHARE_INFO_1 structure.

2

Return information about the shared resource, including name of the resource, type and permissions, password, and number of connections. The bufptr parameter points to a SHARE_INFO_2 structure.

501

Return the name and type of the resource, and a comment associated with the resource. The bufptr parameter points to a SHARE_INFO_501 structure.

502

Return information about the shared resource, including name of the resource, type and permissions, number of connections, and other pertinent information. The bufptr parameter points to a SHARE_INFO_502 structure.

503

Specifies information about the shared resource, including the name of the resource, type and permissions, number of connections, and other pertinent information. The buf parameter points to a SHARE_INFO_503 structure. If the shi503_servername member of this structure is "*", there is no configured server name.

Windows Server 2003 and Windows XP:  This information level is not supported.
1005

Return a value that indicates whether the share is the root volume in a Dfs tree structure. The bufptr parameter points to a SHARE_INFO_1005 structure.

 

bufptr [out]

Pointer to the buffer that receives the data. The format of this data depends on the value of the level parameter. For more information, see Network Management Function Buffers and Network Management Function Buffer Lengths.

This buffer is allocated by the system and must be freed using the NetApiBufferFree function. Note that you must free the buffer even if the function fails with ERROR_MORE_DATA.

Return value

If the function succeeds, the return value is NERR_Success.

If the function fails, the return value can be one of the following error codes.

Return codeDescription
ERROR_ACCESS_DENIED

The user does not have access to the requested information.

ERROR_INVALID_LEVEL

The value specified for the level parameter is not valid.

ERROR_INVALID_PARAMETER

The specified parameter is not valid.

ERROR_MORE_DATA

More entries are available. Specify a large enough buffer to receive all entries.

ERROR_NOT_ENOUGH_MEMORY

Insufficient memory is available.

NERR_BufTooSmall

The supplied buffer is too small.

NERR_NetNameNotFound

The share name does not exist.

 

Remarks

This function applies only to Server Message Block (SMB) shares. For other types of shares, such as Distributed File System (DFS) or WebDAV shares, use Windows Networking (WNet) functions, which support all types of shares.

For interactive users (users who are logged on locally to the machine), no special group membership is required to execute the NetShareGetInfo function. For non-interactive users, Administrator, Power User, Print Operator, or Server Operator group membership is required to successfully execute the NetShareEnum function at levels 2, 502, and 503. No special group membership is required for level 0 or level 1 calls.

Windows Server 2003 and Windows XP:  For all users, Administrator, Power User, Print Operator, or Server Operator group membership is required to successfully execute the NetShareGetInfo function at levels 2 and 502.

If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to achieve the same functionality you can achieve by calling the network management share functions. For more information, see IADsFileShare.

If 503 is specified for the level parameter, the remote server specified in the shi503_servername member of the SHARE_INFO_503 structure must have been bound to a transport protocol using the NetServerTransportAddEx function. In the call to NetServerTransportAddEx, either 2 or 3 must have been specified for the level parameter, and the SVTI2_SCOPED_NAME flag must have been specified in the SERVER_TRANSPORT_INFO_2 structure for the transport protocol.

Examples

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.


#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <stdio.h>
#include <lm.h>

#pragma comment(lib, "Netapi32.lib")
#pragma comment(lib, "Advapi32.lib")

void wmain( int argc, TCHAR *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:
      printf("Usage: NetShareGetInfo sharename <servername>\n");
      return;
   }
   //
   // Call the NetShareGetInfo function, specifying level 502.
   //
   if((res = NetShareGetInfo (lpszServer,lpszShare,502,(LPBYTE *) &BufPtr)) == ERROR_SUCCESS)
   {
      //
      // Print the retrieved data.
      //
      printf("%S\t%S\t%u\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))
         printf("It has a valid Security Descriptor.\n");
      else
         printf("It does not have a valid Security Descriptor.\n");
      //
      // Free the allocated memory.
      //
      NetApiBufferFree(BufPtr);
   }
   else 
      printf("Error: %ld\n",res);
   return;
}


Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Header

Lmshare.h (include Lm.h)

Library

Netapi32.lib

DLL

Netapi32.dll

See also

Network Management Overview
Network Management Functions
Network Share Functions
NetServerTransportAddEx
SHARE_INFO_0
SHARE_INFO_1
SHARE_INFO_2
SHARE_INFO_501
SHARE_INFO_502
SHARE_INFO_503
SHARE_INFO_1005
SECURITY_DESCRIPTOR

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Potential memory leak in example
The example given seems to contain a potential memory leak (or at least it did when I wrote this comment). From the documentation above: "Note that you must free the buffer even if the function fails with ERROR_MORE_DATA." However, the example calls NetApiBufferFree only if the return value is ERROR_SUCCESS. I've noticed that if the function fails it sets the output pointer you give it (bufptr) to null. If you call NetApiBufferFree with the value null it seems to do no harm. So I just always call NetApiBufferFree to be safe.