<div class="content"><p> </p><p>The NetrShareAdd method shares a <span><a href="1709f6a7-efb8-4ded-b7ae-5cee9ee36320#gt_434b0234-e970-4e8c-bdfa-e16a30d96703" data-linktype="relative-path">server</a></span> resource.</p><dl>
<dd>
<div><pre> NET_API_STATUS NetrShareAdd(
   [in, string, unique] SRVSVC_HANDLE ServerName,
   [in] DWORD Level,
   [in, switch_is(Level)] LPSHARE_INFO InfoStruct,
   [in, out, unique] DWORD* ParmErr
 );
</pre></div>
</dd></dl><p><b>ServerName: </b>An <span><a href="5f8329ee-1965-4ea1-ad35-3b29fbb63232" data-linktype="relative-path">SRVSVC_HANDLE (section 2.2.1.1)</a></span>
pointer that identifies the server. The <span><a href="1709f6a7-efb8-4ded-b7ae-5cee9ee36320#gt_60e0e1fa-66fe-41e1-b5e3-ceab97e53506" data-linktype="relative-path">client</a></span> MUST map this
structure to an RPC binding handle (see <span><a href="https://go.microsoft.com/fwlink/?LinkId=89824" data-linktype="external">[C706]</a></span> sections
4.3.5 and 5.1.5.2). The server MUST ignore this parameter.</p><p><b>Level: </b>Specifies the information level of the
data. This parameter MUST be one of the following values. </p><dl>
<dd>
<table><thead>
  <tr>
   <th>
   <p>Value</p>
   </th>
   <th>
   <p>Meaning</p>
   </th>
  </tr>
 </thead><tbody><tr>
  <td>
  <p>2</p>
  </td>
  <td>
  <p>The buffer is of type <span><a href="baead467-920e-4278-853b-bbd303aadfd6" data-linktype="relative-path">SHARE_INFO_2</a></span>.</p>
  </td>
 </tr><tr>
  <td>
  <p>502</p>
  </td>
  <td>
  <p>The buffer is of type <span><a href="8605fd54-6ede-4316-b30d-ecfafa133c1d" data-linktype="relative-path">SHARE_INFO_502_I</a></span>.</p>
  </td>
 </tr><tr>
  <td>
  <p>503</p>
  </td>
  <td>
  <p>The buffer is of type <span><a href="0448e06c-91b2-4ca6-bd9c-02ed396a3fbc" data-linktype="relative-path">SHARE_INFO_503_I</a></span>.</p>
  </td>
 </tr></tbody></table>
</dd></dl><p><b>InfoStruct: </b>A pointer to the <span><a href="419f538b-9342-455e-9b8c-fa430e77bc54" data-linktype="relative-path">SHARE_INFO</a></span>
union. The contents of the <i>InfoStruct</i> parameter depend on the value of
the <i>Level</i> parameter. The client MUST set the STYPE_CLUSTER_FS,
STYPE_CLUSTER_SOFS, and STYPE_CLUSTER_DFS bits in the shi*_type field of the
SHARE_INFO union to zero; the server MUST ignore them on receipt.</p><p><b>ParmErr: </b>A pointer to a value that receives
the index of the first member of the share information structure that caused an
ERROR_INVALID_PARAMETER error code, if it occurs.</p><p><b>Return Values: </b>The method returns 0x00000000
(NERR_Success) to indicate success; otherwise, it returns a nonzero error code.
The method can take any specific error code value, as specified in <span><a href="../ms-erref/1bc92ddf-b79e-413c-bbaa-99a5281a6c90" data-linktype="relative-path">[MS-ERREF]</a></span>
section <span><a href="../ms-erref/18d8fbe8-a967-4f1c-ae50-99ca8e491d2d" data-linktype="relative-path">2.2</a></span>.
The most common error codes are listed in the following table.</p><dl>
<dd>
<table><thead>
  <tr>
   <th>
   <p>Return value/code</p>
   </th>
   <th>
   <p>Description</p>
   </th>
  </tr>
 </thead><tbody><tr>
  <td>
  <p>0x00000000</p>
  <p>NERR_Success</p>
  </td>
  <td>
  <p>The client request succeeded.</p>
  </td>
 </tr><tr>
  <td>
  <p>0x00000005</p>
  <p>ERROR_ACCESS_DENIED</p>
  </td>
  <td>
  <p>Access is denied.</p>
  </td>
 </tr><tr>
  <td>
  <p>0x0000007C</p>
  <p>ERROR_INVALID_LEVEL</p>
  </td>
  <td>
  <p>The system call level is not correct.</p>
  </td>
 </tr><tr>
  <td>
  <p>0x0000007B</p>
  <p>ERROR_INVALID_NAME</p>
  </td>
  <td>
  <p>The file name, directory name, or volume label syntax
  is incorrect.</p>
  </td>
 </tr><tr>
  <td>
  <p>0x00000057</p>
  <p>ERROR_INVALID_PARAMETER</p>
  </td>
  <td>
  <p>The client request failed because the specified
  parameter is invalid. For details, see the description that follows for the <i>ParmErr</i>
  parameter.</p>
  </td>
 </tr><tr>
  <td>
  <p>0x00000008</p>
  <p>ERROR_NOT_ENOUGH_MEMORY</p>
  </td>
  <td>
  <p>Not enough storage is available to process this
  command.</p>
  </td>
 </tr><tr>
  <td>
  <p>0x00000846</p>
  <p>NERR_DuplicateShare</p>
  </td>
  <td>
  <p>The share name is already in use on this server.</p>
  </td>
 </tr><tr>
  <td>
  <p>0x00000844</p>
  <p>NERR_UnknownDevDir</p>
  </td>
  <td>
  <p>The device or directory does not exist.</p>
  </td>
 </tr></tbody></table>
</dd></dl><p>In response to a NetrShareAdd message, the server MUST share
a server resource or return an error code. A shared resource is a local
resource on a server (for example, a disk directory, print device, or <span><a href="1709f6a7-efb8-4ded-b7ae-5cee9ee36320#gt_34f1dfa8-b1df-4d77-aa6e-d777422f9dca" data-linktype="relative-path">named
pipe</a></span>) that can be accessed by users and applications on the network.</p><p>The <i>Level</i> parameter determines the type of structure
that the client has used to specify information about the new share. The value
of the <i>Level</i> parameter MUST be 2, 502, or 503. If the <i>Level</i>
parameter is not one of the valid values, the server MUST fail the call with an
ERROR_INVALID_LEVEL error code.</p><p>If the <i>Level</i> parameter is 2, InfoStruct contains a SHARE_INFO_2
structure.</p><p>If the <i>Level</i> parameter is 502, InfoStruct contains a
SHARE_INFO_502_I structure.</p><p>If the <i>Level</i> parameter is 503, InfoStruct contains a
SHARE_INFO_503_I structure.</p><p>The name of the share to be added is specified in the
shi*_netname member of the SHARE_INFO structure. If the specified share name is
an empty string, or is a nonempty string of length greater than 80 characters,
the server MUST fail the call with an ERROR_INVALID_PARAMETER error code. If
the specified share name is &#34;pipe&#34; or &#34;mailslot&#34;, the
server MUST fail the call with an ERROR_ACCESS_DENIED error code.</p><p>If <i>Level</i> is 2 or 502, the server MUST look up the <b>Share</b>
in <b>ShareList</b>, where <b>Share.ShareName</b> matches shi*_netname and <b>Share.ServerName</b>
matches &#34;*&#34;.</p><p>If <i>Level</i> is 503, the server MUST look up the <b>Share</b>
in <b>ShareList</b>, where <b>Share.ShareName</b> matches shi503_netname and <b>Share.ServerName</b>
matches shi503_servername.</p><p>If a matching <b>Share</b> is found, the server MUST fail
the call with NERR_DuplicateShare.</p><p>The server MUST validate all information that is provided in
the SHARE_INFO (section 2.2.3.6) structure, and if any SHARE_INFO
structure member is found to be invalid, the server MUST fail the call with an
ERROR_INVALID_PARAMETER error code.</p><p>The server performs the following validation on the
structure:</p><ul><li><p><span><span> 
</span></span>shi*_netname must not be a NULL (zero-length) string, and its
length must not be greater than 80 characters.</p>
</li><li><p><span><span> 
</span></span>If Level=502 and a security descriptor is provided, it must be a
valid security descriptor.</p>
</li><li><p><span><span> 
</span></span>If shi*_netname specifies an IPC$ or the ADMIN$ share, shi*_path
must be NULL; otherwise, shi*_path must be a nonempty string that specifies a
valid share path (must not have &#34;.&#34; and &#34;..&#34; appear as
directory names).</p>
</li><li><p><span><span> 
</span></span>If shi*_netname specifies an NT path (begins with
&#34;\\?\&#34;), shi*_type must not have a STYPE_DISKTREE flag.</p>
</li><li><p><span><span> 
</span></span>If shi*_remark is specified, its length must not be greater than
48.</p>
</li><li><p><span><span> 
</span></span>If shi*_ type specifies a STYPE_DISKTREE flag and shi*_netname is
not an ADMIN$ share, shi*_path must specify an absolute directory path. If the
server does not support shared net drivers (determined by the SERVER_INFO field
sv*_enablesharednetdrives), the path must not be on a network drive.</p>
</li><li><p><span><span> 
</span></span>If a disk share is being added, the directory to be shared must
exist and the caller must have access to it.</p>
</li></ul><p>If the <i>ParmErr</i> parameter is not NULL and the server
finds a member of the SHARE_INFO structure to be invalid, the server MUST set <i>ParmErr</i>
to a value that denotes the index of the member that was found to have an
invalid value and fail the call with an ERROR_INVALID_PARAMETER (0x00000057)
error code. The mapping between the values to set and the corresponding member
is listed in section <span><a href="a7020e54-4c40-4cd3-8d2f-f624afb3b86e" data-linktype="relative-path">2.2.2.11</a></span>.</p><p>If the <i>ParmErr</i> parameter is NERR_Success, the server
MUST create a <b>Share</b> and insert it into <b>ShareList</b> with the
following fields set:</p><ul><li><p><span><span> 
</span></span>If the <b>STYPE_TEMPORARY</b> field is set in shi*_type, <b>Share.IsPersistent</b>
MUST be set to FALSE. Otherwise, <b>Share.IsPersistent</b> MUST be set to TRUE.</p>
</li><li><p><span><span> 
</span></span><b>Share.IsMarkedForDeletion</b> MUST be set to FALSE.</p>
</li><li><p><span><span> 
</span></span><b>Share.IsPrinterShare</b> MUST be set to TRUE if shi*_ type
specifies STYPE_PRINTQ flag.</p>
</li><li><p><span><span> 
</span></span><b>Share.ShareName</b> MUST be set to shi*_netname.</p>
</li><li><p><span><span> 
</span></span><b>Share.ServerName</b> MUST be set to shi503_servername if it is
specified and if <i>Level</i> is equal to 503; otherwise it MUST be set to
&#34;*&#34;.</p>
</li><li><p><span><span> 
</span></span><b>Share.LocalPath</b> MUST be set to shi*_path.</p>
</li><li><p><span><span> 
</span></span><b>Share.FileSecurity</b> MUST be set to shi*_security_descriptor
if it is specified and if Level is equal to 502 or 503; otherwise it MUST be
set to NULL.</p>
</li><li><p><span><span> 
</span></span><b>Share.CscFlags</b> MUST be set to 0.</p>
</li><li><p><span><span> 
</span></span><b>Share.IsDfs</b> MUST be set to FALSE.</p>
</li><li><p><span><span> 
</span></span><b>Share.DoAccessBasedDirectoryEnumeration</b> MUST be set to
FALSE.</p>
</li><li><p><span><span> 
</span></span><b>Share.AllowNamespaceCaching</b> MUST be set to FALSE.</p>
</li><li><p><span><span> 
</span></span><b>Share.ForceSharedDelete</b> MUST be set to FALSE.</p>
</li><li><p><span><span> 
</span></span><b>Share.RestrictExclusiveOpens</b> MUST be set to FALSE.</p>
</li><li><p><span><span> 
</span></span><b>Share.Type</b> MUST be set to shi*_type.</p>
</li><li><p><span><span> 
</span></span><b>Share.Remark</b> MUST be set to shi*_remark.</p>
</li><li><p><span><span> 
</span></span><b>Share.MaxUses</b> MUST be set to 0xFFFF if shi*_max_uses is not
specified; otherwise it MUST be set to shi*_max_uses.</p>
</li><li><p><span><span> 
</span></span><b>Share.CurrentUses</b> MUST be set to 0.</p>
</li><li><p><span><span> 
</span></span><b>Share.ForceLevel2Oplock</b> MUST be set to FALSE.</p>
</li></ul><p>If shi*_ type specifies STYPE_PRINTQ flag, <b>PrinterShareCount</b>
MUST be increased by 1, and the server MUST invoke the events as specified in
section <span><a href="ecb840a3-bbec-470d-b740-73540c1a9293" data-linktype="relative-path">3.1.6.9</a></span>, providing
SV_TYPE_PRINTQ_SERVER as the input parameter.</p><p>The server MUST construct a share in SHARE_INFO_503_I
structure as the input parameter to register the share by invoking underlying
server event as specified in <span><a href="../ms-cifs/d416ff7c-c536-406e-a951-4f04b2fd1d2b" data-linktype="relative-path">[MS-CIFS]</a></span>
section <span><a href="../ms-cifs/644bbaa1-8e9e-4634-b1e4-e8e508e3f861" data-linktype="relative-path">3.3.4.9</a></span>
and <span><a href="../ms-smb2/5606ad47-5ee0-437a-817e-70c366052962" data-linktype="relative-path">[MS-SMB2]</a></span>
section <span><a href="../ms-smb2/f9f8e79e-2f29-4e06-b3e5-78e28a3436bc" data-linktype="relative-path">3.3.4.13</a></span>,
providing <i>share</i> as the input parameter. The fields in share MUST be set
as follows:</p><ul><li><p><span><span> 
</span></span><b>share.shi503_netname</b> MUST be set to <b>Share.ShareName</b>.</p>
</li><li><p><span><span> 
</span></span><b>share.shi503_type</b> MUST be set to <b>Share.Type</b>.</p>
</li><li><p><span><span> 
</span></span><b>share.shi503_remark</b> MUST be set to <b>Share.Remark</b>.</p>
</li><li><p><span><span> 
</span></span><b>share.shi503_permissions</b> MUST be set to 0.</p>
</li><li><p><span><span> 
</span></span><b>share.shi503_max_uses</b> MUST be set to <b>Share.MaxUses</b>.</p>
</li><li><p><span><span> 
</span></span><b>share.shi503_current_uses</b> MUST be set to 0.</p>
</li><li><p><span><span> 
</span></span><b>share.shi503_path</b> MUST be set to <b>Share.LocalPath</b>.</p>
</li><li><p><span><span> 
</span></span><b>share.shi503_passwd</b> MUST be set to NULL.</p>
</li><li><p><span><span> 
</span></span><b>share.shi503_security_descriptor</b> MUST be set to <b>Share.FileSecurity</b>.</p>
</li><li><p><span><span> 
</span></span><b>share.shi503_servername</b> MUST be set to <b>Share.ServerName</b>.</p>
</li></ul><p>If either the CIFS or the SMB2 server returns an error:</p><ul><li><p><span><span> 
</span></span>The server MUST remove the Share from ShareList and free the
share object.</p>
</li><li><p><span><span> 
</span></span>The server MUST invoke the underlying server events as specified
in [MS-CIFS] section <span><a href="../ms-cifs/7c96c13d-e5de-4326-a9c7-aae97250a66a" data-linktype="relative-path">3.3.4.11</a></span>
and [MS-SMB2] section <span><a href="../ms-smb2/9b634aad-c492-4c27-9918-4ef2e7aef76d" data-linktype="relative-path">3.3.4.15</a></span>,
providing tuple &lt;Share.ServerName, Share.ShareName&gt; as input parameters.</p>
</li><li><p><span><span> 
</span></span>If the error returned by the CIFS or the SMB2 server is
STATUS_INVALID_PARAMETER, then the server MUST fail the call with
ERROR_INVALID_DATA (0x0000000D). Otherwise, the server MUST fail the call with
NERR_DuplicateShare.</p>
</li></ul><p>If <b>Share.IsPersistent</b> is TRUE, the server MUST
persist the <b>Share</b> to a persistent configuration store. If a share with
the same ShareName already exists in the store, the preexisting entry MUST be
overwritten with this entry.</p><p>The server SHOULD<a id="Appendix_A_Target_55"></a><a aria-label="Product behavior note 55" href="ebb74ff2-abb1-4e1b-a76a-563a5cbbea9a#Appendix_A_55" data-linktype="relative-path">&lt;55&gt;</a> enforce
the security measures to verify that the caller has the required permissions to
execute this call. If the caller does not have the required credentials, the
server SHOULD<a id="Appendix_A_Target_56"></a><a aria-label="Product behavior note 56" href="ebb74ff2-abb1-4e1b-a76a-563a5cbbea9a#Appendix_A_56" data-linktype="relative-path">&lt;56&gt;</a> fail the call.</p></div>