<div class="content" name="CreateApplication" uuid="20be5a58-6604-4a94-ab26-2809d7fb0d24"><p>The CreateApplication method creates a new application at
the specified <a href="1243ba70-74ca-44f9-be0b-dfd6697010b4#gt_086b13f2-2715-4000-a16c-6acc3d59cc19" data-linktype="relative-path">metabase</a>
path.</p><dl>
<dd>
<div><pre> HRESULT CreateApplication(
   [in, unique, string] LPCWSTR szMDPath,
   [in] DWORD dwAppMode,
   [in, unique, string] LPCWSTR szAppPoolId,
   [in] BOOL fCreatePool
 );
</pre></div>
</dd></dl><p><b>szMDPath: </b>A pointer to a Unicode string that
contains the metabase path of the application.</p><p><b>dwAppMode: </b> An unsigned 32-bit integer value
indicating the process where the application will run. This parameter MUST be
set to 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>eAppRunInProc 0x00000000</td>
  <td>The application runs in the IIS parent process.</td>
 </tr><tr>
  <td>eAppRunOutProcIsolated 0x00000001</td>
  <td>The application runs in its own process.</td>
 </tr><tr>
  <td>eAppRunOutProcInDefaultPool 0x00000002</td>
  <td>The application runs in a shared process with other applications outside of the IIS parent process.</td>
 </tr></tbody></table>
</dd></dl><p><b>szAppPoolId: </b>A pointer to a Unicode string
that specifies the application pool name with which to associate the new application.</p><p><b>fCreatePool: </b>A flag indicating whether to
create a new application pool if the pool specified by the <i>szAppPoolId</i>
parameter does not exist (TRUE) or to use an existing application pool (FALSE).</p><p><b>Return Values: </b> A signed 32-bit value that
indicates return status. If the method returns a negative value, it failed. If
the 12-bit facility code (bits 16–27) is set to 0x007, the value contains a
Win32 error code in the lower 16 bits. Zero or positive values indicate
success, with the lower 16 bits in positive nonzero values containing warnings
or flags defined in the method implementation. For more information about Win32
error codes and <a href="../ms-dtyp/a9046ed2-bfb2-4d56-a719-2824afce59ac" data-linktype="relative-path">HRESULT</a>
values, see <a href="../ms-erref/1bc92ddf-b79e-413c-bbaa-99a5281a6c90" data-linktype="relative-path">[MS-ERREF]</a>.
</p><dl>
<dd>
<table><thead>
  <tr>
   <th>
   <p>Return value/code</p>
   </th>
   <th>
   <p>Description</p>
   </th>
  </tr>
 </thead><tbody><tr>
  <td>0x00000000 S_OK</td>
  <td>The call was successful.</td>
 </tr><tr>
  <td>0x80070057 E_INVALIDARG</td>
  <td>One or more arguments are invalid.</td>
 </tr><tr>
  <td>0x80070490 ERROR_NOT_FOUND</td>
  <td>Element not found.</td>
 </tr></tbody></table>
</dd></dl><p>The <a href="1243ba70-74ca-44f9-be0b-dfd6697010b4#gt_e127848e-c66d-427d-b3aa-9f904fa4ada7" data-linktype="relative-path">opnum</a>
field value for this method is 3. </p><p>When processing this call, the server MUST do the following:</p><ul><li><p><span><span> 
</span></span>The <a href="1243ba70-74ca-44f9-be0b-dfd6697010b4#gt_434b0234-e970-4e8c-bdfa-e16a30d96703" data-linktype="relative-path">server</a>
SHOULD validate that the metabase path specified in the <i>szMDPath</i>
parameter is a valid application path.<a id="Appendix_A_Target_29"></a><a aria-label="Product behavior note 29" href="88fd1df0-e63e-41ca-9bf3-bedcab57cd86#Appendix_A_29" data-linktype="relative-path">&lt;29&gt;</a></p>
</li><li><p><span><span> 
</span></span>If the string length of the <i>szMDPath</i> parameter is &lt;=
10, return E_INVALIDARG.</p>
</li><li><p><span><span> 
</span></span>Check that the path specified in <i>szMDPath</i> exists in the
metabase. If it does not, create it.</p>
</li><li><p><span><span> 
</span></span>If the path exists, check to see whether an application is
defined on the path. If an application is already defined at this metabase path
and the value of <a href="5df9ca57-2a81-4ff4-97d5-fd39aa6731af" data-linktype="relative-path">MD_APP_ISOLATED</a>
does not match the value specified by the <i>dwAppMode</i> parameter, delete
the current application (see section <a href="f4683981-4b25-46fa-9017-90cb0f08466c" data-linktype="relative-path">3.7.4.2</a>).</p>
</li><li><p><span><span> 
</span></span>Create the new application. </p>
</li><li><p><span><span> 
</span></span>Set the MD_APP_ISOLATED property on the specified metabase path
to the value specified in the <i>dwAppMode</i> parameter.</p>
</li><li><p><span><span> 
</span></span>Set the <a href="941aefe0-7996-4614-ac1e-b899c6ff8b7e" data-linktype="relative-path">MD_APP_ROOT</a>
property on the specified metabase path to the value of <i>szMDPath</i> without
any trailing &#39;/&#39; if one was specified.</p>
</li><li><p><span><span> 
</span></span>If <i>szAppPoolId</i> is NULL and <i>fCreatePool</i> is FALSE,
return S_OK.</p>
</li><li><p><span><span> 
</span></span>If <i>fCreatePool</i> is TRUE, create an application pool with
name <i>szAppPoolId</i> (see section <a href="57d64120-4037-4a50-bf2d-d8aa4db59020" data-linktype="relative-path">3.9.4.3</a>).</p>
</li><li><p><span><span> 
</span></span>If <i>fCreatePool</i> is FALSE and no application pool exists
with the name <i>szAppPoolId</i>, return ERROR_NOT_FOUND.</p>
</li><li><p><span><span> 
</span></span>Set the <a href="ea447b9c-be00-435c-88b2-c01bbb4fe4ff" data-linktype="relative-path">MD_APP_APPPOOL_ID</a>
property on the specified metabase path to the value of <i>szAppPoolId</i>.</p>
</li></ul></div>