<div class="content"><p>RpcAddPrinterEx installs a printer on the <a href="831cd729-be7c-451e-b729-bd8d84ce4d24#gt_59fb3ddc-63cf-45df-8a90-46a6af9e00cb" data-linktype="relative-path">print server</a>.<a id="Appendix_A_Target_288"></a><a aria-label="Product behavior note 288" href="e81cbc09-ab05-4a32-ae4a-8ec57b436c43#Appendix_A_288" data-linktype="relative-path">&lt;288&gt;</a></p><dl>
<dd>
<div><pre> DWORD RpcAddPrinterEx(
   [in, string, unique] STRING_HANDLE pName,
   [in] PRINTER_CONTAINER* pPrinterContainer,
   [in] DEVMODE_CONTAINER* pDevModeContainer,
   [in] SECURITY_CONTAINER* pSecurityContainer,
   [in] SPLCLIENT_CONTAINER* pClientInfo,
   [out] PRINTER_HANDLE* pHandle
 );
</pre></div>
</dd></dl><p><b>pName: </b>A parameter specified in <a href="acb355a4-913b-4abb-8cb5-415aea160015" data-linktype="relative-path">Print Server Name
Parameters (section 3.1.4.1.4)</a>.</p><p><b>pPrinterContainer: </b>A parameter specified in <a href="07b78bd9-247c-4c58-981e-9a77538238ae" data-linktype="relative-path">PRINTER_CONTAINER
Parameters (section 3.1.4.1.8.6)</a>. The <b>Level</b> member of the <a href="ad7d4d4e-0feb-45e0-93ed-b3b2b9a313d1" data-linktype="relative-path">PRINTER_CONTAINER</a> MUST be
0x00000001 or 0x00000002.</p><p><b>pDevModeContainer: </b>A parameter specified in <a href="bf31abc0-da86-4ac6-8ebc-8be665e11503" data-linktype="relative-path">DEVMODE_CONTAINER
Parameters (section 3.1.4.1.8.1)</a>.</p><p><b>pSecurityContainer: </b>A parameter specified in <a href="6c605144-1c00-4365-a6c7-5499676dcb52" data-linktype="relative-path">SECURITY_CONTAINER
Parameters (section 3.1.4.1.8.7)</a>.</p><p><b>pClientInfo: </b>A parameter specified in <a href="e6a9e216-bc2c-4320-9f67-ac3866fb2bc5" data-linktype="relative-path">SPLCLIENT_CONTAINER
Parameters (section 3.1.4.1.8.8)</a>.</p><p><b>pHandle: </b>A pointer to a variable that MUST
receive the printer <a href="831cd729-be7c-451e-b729-bd8d84ce4d24#gt_9dfe84e3-a772-4ad1-9a25-1255c1dc0f84" data-linktype="relative-path">remote
procedure call (RPC) context handle</a> to the printer object added. RPC
context handles are specified in <a href="https://go.microsoft.com/fwlink/?LinkId=89824" data-linktype="external">[C706]</a>.</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 <a href="../ms-erref/1bc92ddf-b79e-413c-bbaa-99a5281a6c90" data-linktype="relative-path">[MS-ERREF]</a>.</p><p>Upon receiving this message, the server MUST validate
parameters as follows:</p><ul><li><p><span><span> 
</span></span>Perform the validation steps specified in Print Server Name
Parameters.</p>
</li><li><p><span><span> 
</span></span>Perform the validation steps specified in PRINTER_CONTAINER
Parameters.</p>
</li><li><p><span><span> 
</span></span>Perform the validation steps specified in DEVMODE_CONTAINER
Parameters.</p>
</li><li><p><span><span> 
</span></span>Perform the validation steps specified in SECURITY_CONTAINER
Parameters.</p>
</li><li><p><span><span> 
</span></span>Perform the validation steps specified in SPLCLIENT_CONTAINER
Parameters.</p>
</li><li><p><span><span> 
</span></span>If the value of the <b>Level</b> member of the PRINTER_CONTAINER
that is pointed to by the <i>pPrinterContainer</i> parameter is 0x00000002:</p>
<ul><li><p><span><span>  </span></span>Verify
that the <a href="831cd729-be7c-451e-b729-bd8d84ce4d24#gt_1a48eebd-e72c-494d-b8cb-84dfb7bc3b65" data-linktype="relative-path">printer driver</a>
specified in the <a href="125fb29b-3c51-41fc-a333-b1e0e8794a91" data-linktype="relative-path">PRINTER_INFO</a>
that is pointed to by the <b>pointer</b> member of the PRINTER_CONTAINER
pointed to by the <i>pPrinterContainer</i> parameter already exists in the
system; if that verification fails, return ERROR_UNKNOWN_PRINTER_DRIVER
[MS-ERREF].</p>
</li><li><p><span><span>  </span></span>Verify
that the <a href="831cd729-be7c-451e-b729-bd8d84ce4d24#gt_ac027425-6043-4ad3-be27-56a381b75d38" data-linktype="relative-path">port</a> specified
in the PRINTER_INFO that is pointed to by the <b>pointer</b> member of the
PRINTER_CONTAINER pointed to by the <i>pPrinterContainer</i> parameter already
exists in the system; if that verification fails, return ERROR_UNKNOWN_PORT
[MS-ERREF].</p>
</li><li><p><span><span>  </span></span>Verify
that the <a href="831cd729-be7c-451e-b729-bd8d84ce4d24#gt_062f3e76-3149-468c-bf64-1535651725d1" data-linktype="relative-path">print processor</a>
specified in the PRINTER_INFO that is pointed to by the <b>pointer</b> member
of the PRINTER_CONTAINER pointed to by the <i>pPrinterContainer</i> parameter
already exists in the system; 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 the <i>pPrinterContainer</i>
parameter does not already exist in the system; 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_289"></a><a aria-label="Product behavior note 289" href="e81cbc09-ab05-4a32-ae4a-8ec57b436c43#Appendix_A_289" data-linktype="relative-path">&lt;289&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
that is pointed to by the <i>pPrinterContainer</i> parameter 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 <a href="1625e9d9-29e4-48f4-b83d-3bd0fdaea787" data-linktype="relative-path">PRINTER_ATTRIBUTE_SHARED</a>
bit is set in the <b>Flags</b> member of the PRINTER_INFO structure pointed to
by the <b>pPrinterInfo1</b> member of the PRINTER_CONTAINER that is pointed to
by the <i>pPrinterContainer</i> parameter, add the printer to the &#34;List of
Known Printers&#34; as specified in <a href="1bd61448-db4b-4284-a4b1-8346732402d4" data-linktype="relative-path">Abstract Data
Model (section 3.1.1)</a>.<a id="Appendix_A_Target_290"></a><a aria-label="Product behavior note 290" href="e81cbc09-ab05-4a32-ae4a-8ec57b436c43#Appendix_A_290" data-linktype="relative-path">&lt;290&gt;</a></p>
</li><li><p><span><span>  </span></span>If
PRINTER_ATTRIBUTE_SHARED is not set in the <b>Flags</b> member of the
PRINTER_INFO structure pointed to by the <b>pPrinterInfo1</b> member of the
PRINTER_CONTAINER that is pointed to by the <i>pPrinterContainer</i> parameter,
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 that is pointed to by <i>pHandle</i>.</p>
</li><li><p><span><span>  </span></span>Return
ERROR_PRINTER_ALREADY_EXISTS [MS-ERREF].</p>
</li></ul><p><b>Note:</b> An error return code
is required by <a href="831cd729-be7c-451e-b729-bd8d84ce4d24#gt_8a7f6700-8311-45bc-af10-82e10accd331" data-linktype="relative-path">remote
procedure call (RPC)</a> because NULL was stored to the output parameter
pointed to by <i>pHandle</i>.</p>
</li><li><p><span><span> 
</span></span>If the value of the <b>Level</b> member of the PRINTER_CONTAINER
that is pointed to by the <i>pPrinterContainer</i> parameter is 0x00000002:</p>
<ul><li><p><span><span>  </span></span>Instead
of failing the validation steps for missing printer driver, port, and print
processor, the server MAY create the required printer driver, port, and print
processor if they do not exist in the system.<a id="Appendix_A_Target_291"></a><a aria-label="Product behavior note 291" href="e81cbc09-ab05-4a32-ae4a-8ec57b436c43#Appendix_A_291" data-linktype="relative-path">&lt;291&gt;</a></p>
</li><li><p><span><span>  </span></span>Create
the printer object and assign to it the security descriptor from the <a href="6cf2b4ff-1b2b-453c-87f9-85243823cea8" data-linktype="relative-path">SECURITY_CONTAINER</a> that is
pointed to by the <i>pSecurityContainer</i> parameter.</p>
</li><li><p><span><span>  </span></span>Add
the printer to the &#34;List of Printers&#34; specified in 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 <b>RPC handle</b>.</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 <a href="ccc2a501-794e-4d2b-b312-f69c75131c2e" data-linktype="relative-path">DEVMODE</a>
that is contained in the <a href="c2b14fe7-6479-4460-a7ba-633a845dd61a" data-linktype="relative-path">DEVMODE_CONTAINER</a>
pointed to by the <i>pDevModeContainer</i> parameter if it is not NULL.</p>
</li><li><p><span><span> 
</span></span>The data from the <a href="cca15c72-57d3-42fc-91e7-49442b623c11" data-linktype="relative-path">SPLCLIENT_CONTAINER</a> that
is pointed to by the <i>pClientInfo</i> parameter if it is not NULL.</p>
</li></ul></li><li><p><span><span>  </span></span>Store
the <b>RPC handle</b> for the session in the output parameter <i>pHandle</i>.
The handle returned from this method MUST be granted <a href="945c4df5-4969-49c5-b1ce-59c1b3f35024" data-linktype="relative-path">PRINTER_ALL_ACCESS</a>
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
any clients are registered for notifications of the server object change, a
notification MUST be broadcast to them.</p>
</li></ul></li><li><p><span><span> 
</span></span>Return the status of the operation.</p>
</li></ul></div>