<div class="content"><p>The CopyKey method copies or moves a node, including its
subnodes and data, to a specified destination. The copied or moved node becomes
a subnode of the destination node.</p><dl>
<dd>
<div><pre> HRESULT CopyKey(
   [in] METADATA_HANDLE hMDSourceHandle,
   [unique, in, string] LPCWSTR pszMDSourcePath,
   [in] METADATA_HANDLE hMDDestHandle,
   [unique, in, string] LPCWSTR pszMDDestPath,
   [in] BOOL bMDOverwriteFlag,
   [in] BOOL bMDCopyFlag
 );
</pre></div>
</dd></dl><p><b>hMDSourceHandle: </b>An unsigned 32-bit integer
value containing an open <a href="1243ba70-74ca-44f9-be0b-dfd6697010b4#gt_086b13f2-2715-4000-a16c-6acc3d59cc19" data-linktype="relative-path">metabase</a>
handle specifying the source node to be copied or moved. </p><p><b>pszMDSourcePath: </b>A pointer to a Unicode string
that contains the path of the node to be copied or moved relative to the path
of the <i>hMDSourceHandle</i> parameter.</p><p><b>hMDDestHandle: </b>An unsigned 32-bit integer
value containing an open metabase handle specifying the destination node of the
moved or copied metabase key.</p><p><b>pszMDDestPath: </b>A pointer to a string that
contains the path of the new or moved node, relative to the <i>hMDDestHandle</i>
parameter.</p><p><b>bMDOverwriteFlag: </b>A Boolean value that
determine the behavior if a node with the same name as source is already a
child of destination node. If TRUE, the existing node and all its data and
children are deleted prior to copying or moving the source. If FALSE, the
existing node, data, and children remain, and the source is merged with that
data. In cases of data conflicts, the source data overwrites the destination
data.</p><p><b>bMDCopyFlag: </b>A Boolean value that specifies
whether to copy or move the specified node. If TRUE, the node is copied. If
FALSE, the node is moved, and the source node is deleted from its original
location.</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>
  <p>0x00000000</p>
  <p>S_OK</p>
  </td>
  <td>
  <p>The call was successful.</p>
  </td>
 </tr><tr>
  <td>
  <p>0x80070003</p>
  <p>ERROR_PATH_NOT_FOUND</p>
  </td>
  <td>
  <p>The system cannot find the path specified.</p>
  </td>
 </tr><tr>
  <td>
  <p>0x80070005</p>
  <p>E_ACCESSDENIED</p>
  </td>
  <td>
  <p>General access denied error.</p>
  </td>
 </tr><tr>
  <td>
  <p>0x80070006</p>
  <p>ERROR_INVALID_HANDLE</p>
  </td>
  <td>
  <p>The handle is invalid.</p>
  </td>
 </tr><tr>
  <td>
  <p>0x80070057</p>
  <p>E_INVALIDARG</p>
  </td>
  <td>
  <p>One or more arguments are invalid.</p>
  </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 7.</p><p>When processing this call, the <a href="1243ba70-74ca-44f9-be0b-dfd6697010b4#gt_434b0234-e970-4e8c-bdfa-e16a30d96703" data-linktype="relative-path">server</a> MUST do the
following:</p><ul><li><p><span><span> 
</span></span>Check the source handle parameter. This handle is valid if it is
either the master root handle or a handle returned from a previous <a href="a54be1d0-009a-493d-a53e-e2f7fbe87293" data-linktype="relative-path">OpenKey</a> call. If the
handle is invalid, return ERROR_INVALID_HANDLE.</p>
</li><li><p><span><span> 
</span></span>Check the destination handle parameter. This handle is valid if
it is either the master root handle or a handle returned from a previous
OpenKey call. If the handle is invalid, return ERROR_INVALID_HANDLE.</p>
</li><li><p><span><span> 
</span></span>The server SHOULD check whether the source and destination
handles are opened with the correct access mask. The destination handle, <i>hMDDestHandle</i>,
SHOULD be opened with write access. If <i>bMDCopyFlag</i> is TRUE the source
handle, <i>hMDSourceHandle</i>, SHOULD be opened with write access, otherwise
it SHOULD be opened with read access. If the handles were not opened with the
correct access, return E_ACCESSDENIED.<a id="Appendix_A_Target_5"></a><a aria-label="Product behavior note 5" href="88fd1df0-e63e-41ca-9bf3-bedcab57cd86#Appendix_A_5" data-linktype="relative-path">&lt;5&gt;</a></p>
</li><li><p><span><span> 
</span></span>Check whether the source relative path points to the existing
node. If not, return ERROR_PATH_NOT_FOUND.</p>
</li><li><p><span><span> 
</span></span>Check whether the destination relative path has the right syntax
and length. If not, return an error.</p>
</li><li><p><span><span> 
</span></span>Check if the destination node exists. If it is true, check
whether the overwrite parameter is set to TRUE. If it is FALSE, then merge
destination data with source data. When there is a conflict in this merge, take
the source data.</p>
</li><li><p><span><span> 
</span></span>If the destination node does not exist, add a new node to the
tree that has the resultant path as a combined path of destination parent node
and destination relative path. If any intermediate nodes are required, the
server creates these nodes. Copy all data from the source path to the
destination path.</p>
</li><li><p><span><span> 
</span></span>If the copy flag is set to FALSE, delete the source node.</p>
</li></ul></div>