<div class="content" name="RpcAddPrinter" uuid="bd0bb8d5-26fd-4705-81f5-614d32b9f38f"><p>RpcAddPrinter adds a printer to the list of supported
printers for a specified server.</p><dl>
<dd>
<div><pre> DWORD RpcAddPrinter(
   [in, string, unique] STRING_HANDLE pName,
   [in] PRINTER_CONTAINER* pPrinterContainer,
   [in] DEVMODE_CONTAINER* pDevModeContainer,
   [in] SECURITY_CONTAINER* pSecurityContainer,
   [out] PRINTER_HANDLE* pHandle
 );
</pre></div>
</dd></dl><p><b>pName: </b>A parameter specified in <span><a href="acb355a4-913b-4abb-8cb5-415aea160015" data-linktype="relative-path">Print
Server Name Parameters (section 3.1.4.1.4)</a></span>.</p><p><b>pPrinterContainer: </b>A parameter specified in <span><a href="07b78bd9-247c-4c58-981e-9a77538238ae" data-linktype="relative-path">PRINTER_CONTAINER
Parameters (section 3.1.4.1.8.6)</a></span>. The <b>Level</b> member
of the PRINTER_CONTAINER MUST be 0x00000001 or 0x00000002.</p><p><b>pDevModeContainer: </b>A parameter specified in <span><a href="bf31abc0-da86-4ac6-8ebc-8be665e11503" data-linktype="relative-path">DEVMODE_CONTAINER
Parameters (section 3.1.4.1.8.1)</a></span>.</p><p><b>pSecurityContainer: </b>A parameter specified in <span><a href="6c605144-1c00-4365-a6c7-5499676dcb52" data-linktype="relative-path">SECURITY_CONTAINER
Parameters (section 3.1.4.1.8.7)</a></span>.</p><p><b>pHandle: </b>A pointer to a variable that receives
the printer <span><a href="831cd729-be7c-451e-b729-bd8d84ce4d24#gt_9dfe84e3-a772-4ad1-9a25-1255c1dc0f84" data-linktype="relative-path">RPC context handle</a></span>
to the printer object added. RPC context handles are specified in <span><a href="https://go.microsoft.com/fwlink/?LinkId=89824" data-linktype="external">[C706]</a></span>.</p><p><b>Return Values: </b>This method MUST return zero
(ERROR_SUCCESS) to indicate successful completion or a nonzero Windows error
code to indicate failure <span><a href="../ms-erref/1bc92ddf-b79e-413c-bbaa-99a5281a6c90" data-linktype="relative-path">[MS-ERREF]</a></span>.</p><p>Upon receiving this message, the server MUST validate
parameters as follows:</p><ul><li><p><span><span> 
</span></span>Perform validation steps as specified in Print Server Name
Parameters (section 3.1.4.1.4).</p>
</li><li><p><span><span> 
</span></span>Perform validation steps as specified in PRINTER_CONTAINER
Parameters (section 3.1.4.1.8.6).</p>
</li><li><p><span><span> 
</span></span>Perform validation steps as specified in DEVMODE_CONTAINER
Parameters (section 3.1.4.1.8.1).</p>
</li><li><p><span><span> 
</span></span>Perform validation steps as specified in SECURITY_CONTAINER
Parameters (section 3.1.4.1.8.7).</p>
</li><li><p><span><span> 
</span></span>If the <b>Level</b> member of the <span><a href="ad7d4d4e-0feb-45e0-93ed-b3b2b9a313d1" data-linktype="relative-path">PRINTER_CONTAINER</a></span>
is 0x00000002:</p>
<ul><li><p><span><span>  </span></span>Verify
that the <span><a href="831cd729-be7c-451e-b729-bd8d84ce4d24#gt_1a48eebd-e72c-494d-b8cb-84dfb7bc3b65" data-linktype="relative-path">printer driver</a></span>
specified in the <span><a href="125fb29b-3c51-41fc-a333-b1e0e8794a91" data-linktype="relative-path">PRINTER_INFO</a></span> that
is pointed to by the <b>pointer</b> member of the PRINTER_CONTAINER pointed to
by <i>pPrinterContainer</i> already exists in the system, and if that
verification fails, return ERROR_UNKNOWN_PRINTER_DRIVER [MS-ERREF].</p>
</li><li><p><span><span>  </span></span>Verify
that the <span><a href="831cd729-be7c-451e-b729-bd8d84ce4d24#gt_ac027425-6043-4ad3-be27-56a381b75d38" data-linktype="relative-path">port</a></span> specified in
the PRINTER_INFO that is pointed to by the <b>pointer</b> member of the
PRINTER_CONTAINER pointed to by <i>pPrinterContainer</i> already exists in the
system, and if that verification fails, return ERROR_UNKNOWN_PORT [MS-ERREF].</p>
</li><li><p><span><span>  </span></span>Verify
that the print processor specified in the PRINTER_INFO that is pointed to by
the <b>pointer</b> member of the PRINTER_CONTAINER pointed to by <i>pPrinterContainer</i>
already exists in the system, and if that verification fails, return
ERROR_UNKNOWN_PRINTPROCESSOR [MS-ERREF].</p>
</li><li><p><span><span>  </span></span>Verify
that the printer with the name specified in the PRINTER_INFO that is pointed to
by the <b>pointer</b> member of the PRINTER_CONTAINER pointed to by <i>pPrinterContainer</i>
does not already exist in the system, and if that verification fails, return
ERROR_PRINTER_ALREADY_EXISTS [MS-ERREF].</p>
</li></ul></li><li><p><span><span> 
</span></span>Additional validation MAY<a id="Appendix_A_Target_269"></a><a aria-label="Product behavior note 269" href="e81cbc09-ab05-4a32-ae4a-8ec57b436c43#Appendix_A_269" data-linktype="relative-path">&lt;269&gt;</a> be
performed.</p>
</li></ul><p>If parameter validation fails, the server MUST fail the
operation immediately and return a nonzero error response to the client.
Otherwise, the server MUST process the message and compose a response to the
client as follows:</p><ul><li><p><span><span> 
</span></span>Perform PRINTER_CONTAINER parameter processing steps as specified
in PRINTER_CONTAINER Parameters (section 3.1.4.1.8.6).</p>
</li><li><p><span><span> 
</span></span>If the value of the <b>Level</b> member of the PRINTER_CONTAINER
is 0x00000001, and if the server does not maintain a &#34;List of Known
Printers&#34;, the server MUST return ERROR_PRINTER_ALREADY_EXISTS [MS-ERREF].
Otherwise, the server MUST continue to process the message and compose a
response to the client as follows:</p>
<ul><li><p><span><span>  </span></span>If
the <span><a href="1625e9d9-29e4-48f4-b83d-3bd0fdaea787" data-linktype="relative-path">PRINTER_ATTRIBUTE_SHARED</a></span>
bit is set in the <b>Flags</b> member of the <span><a href="0d1a296b-7027-441c-8393-8aa5c3764b27" data-linktype="relative-path">PRINTER_INFO_1</a></span>
structure, add the printer<a id="Appendix_A_Target_270"></a><a aria-label="Product behavior note 270" href="e81cbc09-ab05-4a32-ae4a-8ec57b436c43#Appendix_A_270" data-linktype="relative-path">&lt;270&gt;</a> to the
&#34;List of Known Printers&#34; as specified in section <span><a href="1bd61448-db4b-4284-a4b1-8346732402d4" data-linktype="relative-path">3.1.1</a></span>.</p>
</li><li><p><span><span>  </span></span>If
PRINTER_ATTRIBUTE_SHARED bit is not set in the <b>Flags</b> member of the
PRINTER_INFO_1 structure, remove the printer from the &#34;List of Known
Printers&#34;.</p>
</li><li><p><span><span>  </span></span>Store
NULL in the output parameter pointed to by <i>pHandle</i>.</p>
</li><li><p><span><span>  </span></span>Increment
the number of network printers added to this server.</p>
</li><li><p><span><span>  </span></span>Return
ERROR_PRINTER_ALREADY_EXISTS [MS-ERREF].</p>
<p><b>Note:</b> An error return code
is required by <span><a href="831cd729-be7c-451e-b729-bd8d84ce4d24#gt_8a7f6700-8311-45bc-af10-82e10accd331" data-linktype="relative-path">remote procedure call (RPC)</a></span>
because NULL was stored to the output parameter pointed to by <i>pHandle</i>.</p>
</li></ul></li><li><p><span><span> 
</span></span>If the <b>Level</b> member of the PRINTER_CONTAINER is
0x00000002:</p>
<ul><li><p><span><span>  </span></span>Create
the printer object and assign to it the security descriptor from the <span><a href="6cf2b4ff-1b2b-453c-87f9-85243823cea8" data-linktype="relative-path">SECURITY_CONTAINER</a></span>
that is pointed to by <i>pSecurityContainer</i> parameter.</p>
</li><li><p><span><span>  </span></span>Add
the printer to the &#34;List of Printers&#34; (section 3.1.1).</p>
</li><li><p><span><span>  </span></span>Create
a session that includes:</p>
<ul><li><p><span><span> 
</span></span>An RPC handle</p>
</li><li><p><span><span> 
</span></span>A snapshot of the printer data specific to this instance of the
printer invocation.</p>
</li><li><p><span><span> 
</span></span>The data from the <span><a href="ccc2a501-794e-4d2b-b312-f69c75131c2e" data-linktype="relative-path">DEVMODE</a></span> that is
contained in the <span><a href="c2b14fe7-6479-4460-a7ba-633a845dd61a" data-linktype="relative-path">DEVMODE_CONTAINER</a></span>
pointed to by the <i>pDevModeContainer</i> parameter if it is not NULL.</p>
</li></ul></li><li><p><span><span>  </span></span>Store
the RPC handle for the session in the output parameter pointed to by <i>pHandle</i>.
The handle returned from this method MUST be granted <span><a href="945c4df5-4969-49c5-b1ce-59c1b3f35024" data-linktype="relative-path">PRINTER_ALL_ACCESS</a></span>
permission.</p>
</li><li><p><span><span>  </span></span>Increment
the printer&#39;s reference count to prevent deletion.</p>
</li><li><p><span><span>  </span></span>If
there are any clients that are registered for notifications on the server
object change, a notification MUST be sent to those clients.</p>
</li></ul></li><li><p><span><span> 
</span></span>Return the status of the operation.</p>
</li></ul></div>