Platform SDK: Network Management

NetShareSetInfo

The NetShareSetInfo function sets the parameters of a shared resource.

Security Requirements

Only the Administrators local group or Communication, Print, or Server operator group membership is required to successfully execute the NetShareSetInfo function. The Print operator can set information only about Printer queues. The Communication operator can set information only about communication-device queues.

Windows NT/2000: The parameter order is as follows.

NET_API_STATUS NetShareSetInfo(
  LPWSTR servername, 
  LPWSTR netname,    
  DWORD level,       
  LPBYTE buf,        
  LPDWORD parm_err   
);

Windows 95/98: You must specify the size of the information buffer, in bytes, using the cbBuffer parameter. The parameter list is as follows.

extern API_FUNCTION
 NetShareSetInfo(
  const char FAR * pszServer, 
  const char FAR * pszNetName,
  short sLevel,               
  char FAR * pbBuffer,        
  unsigned short cbBuffer,    
  short sParmNum              
);

Parameters

servername
[in] Pointer to a Unicode (Windows NT/2000) or ANSI (Windows 95/98) string specifying the name of the remote server on which the function is to execute. The string must begin with \\. If this parameter is NULL, the local computer is used.
netname
[in] Pointer to a Unicode (Windows NT/2000) or ANSI (Windows 95/98) string specifying the name of the share to set information on.
level
[in] Specifies the information level of the data. This parameter can be one of the following values.

Windows NT/2000: The following levels are valid.
Value Meaning
1 Specifies information about the shared resource, including the name and type of the resource, and a comment associated with the resource. The buf parameter points to a SHARE_INFO_1 structure.
2 Specifies information about the shared resource, including name of the resource, type and permissions, password, and number of connections. The buf parameter points to a SHARE_INFO_2 structure.
502 Specifies information about the shared resource, including name of the resource, type and permissions, number of connections, and other pertinent information. The buf parameter points to a SHARE_INFO_502 structure.
1004 Specifies a comment associated with the shared resource. The buf parameter points to a SHARE_INFO_1004 structure.
1006 Specifies the maximum number of concurrent connections that the shared resource can accommodate. The buf parameter points to a SHARE_INFO_1006 structure.
1501 Specifies the security descriptor associated with the specified share. The buf parameter points to a SHARE_INFO_1501 structure.

Windows 95/98: The following level is valid.
Value Meaning
50 Specifies information about the shared resource, including the name and type of the resource, a comment associated with the resource, and passwords. The pbBuffer parameter points to a share_info_50 structure.

buf
[in] Pointer to the buffer that specifies the data. The format of this data depends on the value of the level parameter.
parm_err
[out] Pointer to a DWORD value that receives the index of the first member of the share information structure that causes the ERROR_INVALID_PARAMETER error. If this parameter is NULL, the index is not returned on error. For more information, see the following Remarks section.

Return Values

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.

Value Meaning
ERROR_ACCESS_DENIED The user does not have access to the requested information.
ERROR_INVALID_LEVEL The value specified for the level parameter is invalid.
ERROR_INVALID_PARAMETER The specified parameter is invalid. For more information, see the following Remarks section.
NERR_NetNameNotFound The share name does not exist.

Remarks

If the NetShareSetInfo function returns ERROR_INVALID_PARAMETER, you can use the parm_err parameter to indicate the first member of the share information structure that is invalid. (A share information structure begins with SHARE_INFO_ and its format is specified by the level parameter.) The following table lists the values that can be returned in the parm_err parameter and the corresponding structure member that is in error. (The prefix shi*_ indicates that the member can begin with multiple prefixes, for example, shi2_ or shi502_.)

Value Member
SHARE_NETNAME_PARMNUM shi*_netname
SHARE_TYPE_PARMNUM shi*_type
SHARE_REMARK_PARMNUM shi*_remark
SHARE_PERMISSIONS_PARMNUM shi*_permissions
SHARE_MAX_USES_PARMNUM shi*_max_uses
SHARE_CURRENT_USES_PARMNUM shi*_current_uses
SHARE_PATH_PARMNUM shi*_path
SHARE_PASSWD_PARMNUM shi*_passwd
SHARE_FILE_SD_PARMNUM shi*_security_descriptor

Windows 95/98: See the NetShareSetInfo Sample (Windows 95/98) topic to view a code sample that demonstrates how to use the NetShareSetInfo function.

Windows NT/2000: The following code sample demonstrates how to set the comment associated with a shared resource using a call to the NetShareSetInfo function. To do this, the sample specifies information level 1004 (SHARE_INFO_1004).

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

void wmain( int argc, TCHAR *argv[ ])
{
   SHARE_INFO_1004 p;
   NET_API_STATUS res;
   DWORD parm_err = 0;

   if(argc<4)
      printf("Usage: SetInfo server share \"remark\"\n");
   else
   {
      //
      // Fill in SHARE_INFO_1004 structure member.
      //
      p.shi1004_remark=argv[3];
      //
      // Call the NetShareSetInfo function,
      //  specifying information level 1004.
      //
      res=NetShareSetInfo(argv[1], argv[2], 1004, (LPBYTE)&p, &parm_err);
      //
      // Display the result of the call.
      //
      if(res==0)
         printf("Remark set.\n");
      else
         printf("Error: %u\tparmerr=%u\n", res, parm_err);
   }
   return;
}

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.

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Requires Windows 95 or later.
  Header: Declared in Lmshare.h (Windows NT/2000) or Svrapi.h (Windows 95/98); include Lm.h (Windows NT/2000).
  Library: Use Netapi32.lib (Windows NT/2000) or Svrapi.lib (Windows 95/98).

See Also

Network Management Overview, Network Management Functions, Share Functions, NetShareGetInfo, SHARE_INFO_1, SHARE_INFO_2, SHARE_INFO_502, SHARE_INFO_1004, SHARE_INFO_1006, SHARE_INFO_1501, share_info_50