<div class="content" name="R_SetData" uuid="d1827f26-03c1-4362-8a50-b8b474c67c96"><p>The R_SetData method sets a data item for a particular node
in the <a href="1243ba70-74ca-44f9-be0b-dfd6697010b4#gt_086b13f2-2715-4000-a16c-6acc3d59cc19" data-linktype="relative-path">metabase</a>.</p><dl>
<dd>
<div><pre> HRESULT R_SetData(
   [in] METADATA_HANDLE hMDHandle,
   [unique, in, string] LPCWSTR pszMDPath,
   [in] METADATA_RECORD* pmdrMDData
 );
</pre></div>
</dd></dl><p><b>hMDHandle: </b>An unsigned 32-bit integer value
specifying a handle to a node in the metabase with write permissions as
returned by the <a href="a54be1d0-009a-493d-a53e-e2f7fbe87293" data-linktype="relative-path">OpenKey</a>
method.</p><p><b>pszMDPath: </b>A pointer to a Unicode string that
contains the path of the node that stores the entry, relative to the path of
the <i>hMDHandle</i> parameter.</p><p><b>pmdrMDData: </b>A pointer to a <a href="10608402-8619-4ea9-be90-d57f21393ce0" data-linktype="relative-path">METADATA_RECORD</a> structure
that contains the data to set.</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>0x80070003 ERROR_PATH_NOT_FOUND</td>
  <td>The system cannot find the path specified.</td>
 </tr><tr>
  <td>0x80070005 E_ACCESSDENIED</td>
  <td>General access denied error.</td>
 </tr><tr>
  <td>0x80070057 E_INVALIDARG</td>
  <td>An invalid parameter value was specified.</td>
 </tr><tr>
  <td>0x800CC808 MD_ERROR_CANNOT_REMOVE_SECURE_ATTRIBUTE</td>
  <td>The METADATA_SECURE attribute cannot be removed from a data item via the R_GetData method. Use the DeleteData method to remove the secure data.</td>
 </tr><tr>
  <td>0x80070008 ERROR_NOT_ENOUGH_MEMORY</td>
  <td>There is not enough memory to complete the operation.</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 9.</p><p>When processing this call, the server MUST do the following:</p><ul><li><p><span><span> 
</span></span>Check whether the handle, <i>hMDHandle</i>, was opened for write
access. If not, return E_ACCESSDENIED.</p>
</li><li><p><span><span> 
</span></span>Check the path of the node indicated by <i>hMDHandle</i> and <i>pszMDPath</i>.
If the path does not exist, return ERROR_PATH_NOT_FOUND.</p>
</li><li><p><span><span> 
</span></span>If data with the specified identifier does not exist at the
specified node, create a new data item as specified by the <i>pmdrMDData</i>
parameter.</p>
</li><li><p><span><span> 
</span></span>If data with the specified identifier does exist at the specified
node, update the data item with the properties and data value specified by the <i>pmdrMDData</i>
parameter. Before updating the existing data item, the server SHOULD check
whether it has the METADATA_SECURE flag set. If this flag is set on the
existing data item but is not set in the <b>dwMDAttributes</b> member of the <i>pmdrMDData</i>
parameter, the server SHOULD NOT update the existing data item and SHOULD
return MD_ERROR_CANNOT_REMOVE_SECURE_ATTRIBUTE.<a id="Appendix_A_Target_17"></a><a aria-label="Product behavior note 17" href="88fd1df0-e63e-41ca-9bf3-bedcab57cd86#Appendix_A_17" data-linktype="relative-path">&lt;17&gt;</a></p>
</li></ul><p>The <i>pbMDData</i> and <i>dwMDDataLen</i> fields of
METADATA_RECORD (referenced by the <i>pmdrMDData</i> parameter) MUST be
interpreted using the following steps:</p><ol><li><p><span>    </span>Check whether
the <i>dwMDAttributes</i> member of the METADATA_RECORD structure has the
METADATA_SECURE secure flag set.</p>
</li><li><p><span>    </span>If the
METADATA_SECURE secure flag is set, the <i>pbMDData</i> member of
METADATA_RECORD structure points to the encrypted data BLOB, and the <i>dwMDDataLen</i>
field is set to the size of the encrypted data. The encrypted data BLOB is
stored in the <a href="bbe15a83-a32d-48a3-9564-8dacea965e83" data-linktype="relative-path">IIS_CRYPTO_BLOB</a>
message format with the <b>BlobSignature</b> field set to
ENCRYPTED_DATA_BLOB_SIGNATURE. </p>
<ul><li><p><span><span>  </span></span>Decrypt
the data pointed to by the <i>pbMDData</i> field based on the procedure
described in section <a href="f9606fd5-4add-4c19-8169-ab860dfa9494" data-linktype="relative-path">3.1.4.1.3</a>.</p>
</li></ul></li><li><p><span>    </span>If the
METADATA_SECURE secure flag is not set, the data referenced by the <i>pbMDData</i>
member of METADATA_RECORD is the cleartext data, and the <i>dwMDDataLen</i>
field is its length.</p>
</li></ol></div>