<div class="content" name="BaseRegOpenKey" uuid="8cb48f55-19e1-4ea2-8d76-dd0f6934f0d9"><p>The BaseRegOpenKey method is called by the client. In
response, the server opens a specified key for access and returns a handle to
it.</p><dl>
<dd>
<div><pre> error_status_t BaseRegOpenKey(
   [in] RPC_HKEY hKey,
   [in] PRRP_UNICODE_STRING lpSubKey,
   [in] DWORD dwOptions,
   [in] REGSAM samDesired,
   [out] PRPC_HKEY phkResult
 );
</pre></div>
</dd></dl><p><b>hKey: </b>A handle to a key that MUST have been
opened previously by using one of the open methods that are specified in
section <a href="053e8515-dbae-47ea-a7c6-6dc054e3a48f" data-linktype="relative-path">3.1.5</a>: <a href="956a3052-6580-43ee-91aa-aaf61726149b" data-linktype="relative-path">OpenClassesRoot</a>, <a href="ec140ed9-4d00-4c03-a15c-c7245a497ed5" data-linktype="relative-path">OpenCurrentUser</a>, <a href="6cef29ae-21ba-423f-9158-05145ac80a5b" data-linktype="relative-path">OpenLocalMachine</a>, <a href="7b514c63-6cad-4fe1-9780-743959e377e6" data-linktype="relative-path">OpenPerformanceData</a>, <a href="694e57f4-da3e-4285-8b71-3181d71d6cd1" data-linktype="relative-path">OpenUsers</a>, BaseRegOpenKey,
<a href="160767d7-83cf-4718-a4f3-d864faee3bb1" data-linktype="relative-path">OpenCurrentConfig</a>, <a href="44954f6d-ef2c-4ec1-a27d-32b9b87e3c8a" data-linktype="relative-path">OpenPerformanceText</a>, <a href="3626fa8a-b20f-4243-bf85-cdb615ed2ca0" data-linktype="relative-path">OpenPerformanceNlsText</a>.</p><p><b>lpSubKey: </b>A pointer to an <a href="c0c90f11-a4c4-496a-ac09-8a8a3697ceef" data-linktype="relative-path">RRP_UNICODE_STRING</a>
structure that MUST contain the name of a key to open. This parameter is always
relative to the key that is specified by the hKey parameter and is a pointer to
a null-terminated string that contains the name of the subkey to open, as
specified in section <a href="508e3d3e-1225-4075-be04-67680ea80497" data-linktype="relative-path">3.1.1</a>.
This key MUST be an existing subkey of the key that is identified by the <i>hKey</i>
parameter.</p><p><b>dwOptions: </b>Registry key options. MUST be the
bitwise OR of any or none of the following values.</p><dl>
<dd>
<table><thead>
  <tr>
   <th>
   <p><b><span>Value</span></b></p>
   </th>
   <th>
   <p><b><span>Meaning</span></b></p>
   </th>
  </tr>
 </thead><tbody><tr>
  <td>REG_OPTION_BACKUP_RESTORE 0x00000004</td>
  <td>Indicates that the caller requests to assert its backup and/or restore privileges.</td>
 </tr><tr>
  <td>REG_OPTION_OPEN_LINK 0x00000008</td>
  <td>Indicates that the caller requests to open the targeted symlink source rather than the symlink target.</td>
 </tr></tbody></table>
</dd>
<dd>
<p> </p>
</dd></dl><p><b>samDesired: </b>A bit field that describes the
requested security access for the handle to the key that is being opened. It
MUST be constructed from one or more of the values that are specified in
section <a href="fefbc801-b141-4bb1-9dcb-bf366da3ae7e" data-linktype="relative-path">2.2.3</a>.</p><p><b>phkResult:</b> A pointer to the handle of the open
key. The server MUST return a NULL for <i>phkResult</i> in case of failure.</p><p><b>Return Values: </b>The method returns 0
(ERROR_SUCCESS) to indicate success; otherwise, it returns a nonzero error
code, as specified in <a href="../ms-erref/1bc92ddf-b79e-413c-bbaa-99a5281a6c90" data-linktype="relative-path">[MS-ERREF]</a>
section <a href="../ms-erref/18d8fbe8-a967-4f1c-ae50-99ca8e491d2d" data-linktype="relative-path">2.2</a>.</p><p>Server Operations</p><p>In response to this request from the client, for a successful
operation, the server SHOULD<a id="Appendix_A_Target_19"></a><a aria-label="Product behavior note 19" href="85f43046-e27d-4122-93ba-bc278f986fbe#Appendix_A_19" data-linktype="relative-path">&lt;19&gt;</a> open the <a href="261b039d-95d9-4749-9680-db1851d03945#gt_2d67ea57-10e6-422f-985e-694834945a02" data-linktype="relative-path">registry</a> key that is
specified by the <i>lpSubKey</i> parameter. In the event of success, the server
MUST create a handle to the new key for this request and return the handle
value in the <i>phkResult</i> parameter.</p><p>If <i>hKey</i> is not an open handle to a key on the server,
the server MUST fail the method and return ERROR_INVALID_HANDLE.</p><p>The server then determines which key namespace to operate on
(KEYS32 or KEYS64) by inspecting the value of the <i>samDesired</i> parameter.
If the server does not support the 64-bit key namespace (see section <a href="d962e3a6-30e1-4bb3-9663-cd4751604212" data-linktype="relative-path">3.1.1.4</a>), the server MUST
operate on the 32-bit key namespace (KEYS32).</p><p>If the server is a 64-bit registry server and supports both
the 32-bit and 64-bit key namespaces, as defined in section 3.1.1.4, the server
MUST first check if both the KEY_WOW64_64KEY and KEY_WOW64_32KEY bits are set
in the <i>samDesired</i> parameter. If both KEY_WOW64_64KEY and KEY_WOW64_32KEY
are set, the server SHOULD<a id="Appendix_A_Target_20"></a><a aria-label="Product behavior note 20" href="85f43046-e27d-4122-93ba-bc278f986fbe#Appendix_A_20" data-linktype="relative-path">&lt;20&gt;</a> fail the
method and return ERROR_INVALID_PARAMETER.</p><p>The server then checks to see if the key specified by the
hKey parameter is a key that can only be operated on in the 64-bit key
namespace (KEYS64). See section 3.1.1.4.</p><p>If the key specified by the <i>hKey</i> parameter is a key
that can only be operated on in the 64-bit key namespace (KEYS64), the server
MUST ignore the KEY_WOW64_64KEY and KEY_WOW64_32KEY bits in the <i>samDesired</i>
parameter and operate on and create or open the key in the 64-bit namespace
(KEYS64).</p><p>If the key specified by <i>lpSubKey</i> has a KEYTYPE of symbolic
link and the client has not set REG_OPTION_OPEN_LINK in the <i>dwOptions</i>
parameter, the server MUST return a handle to the key that is the target of the
symbolic link (see section <a href="d5ce9dcc-1f90-4f5a-b076-cc1d2c9b4195" data-linktype="relative-path">3.1.1.11</a>).
The server first checks for a value of the key indicated by <i>lpSubKey</i>
named &#34;SymbolicLinkValue&#34;. If a value named SymbolicLinkValue is not
found, the server MUST fail the method and return ERROR_INVALID_PARAMETER. If
the target of the symbolic link does not exist, the server MUST fail the method
and return ERROR_INVALID_PARAMETER.</p><p>If the key specified by <i>lpSubKey</i> has a KEYTYPE of
symbolic link and the client has set REG_OPTION_OPEN_LINK in the <i>dwOptions</i>
parameter, the server returns a handle to the key that is the source of the
symbolic link.</p><p>If the <i>lpSubKey</i> parameter is a pointer to an empty <b>WCHAR</b>
array, the method returns a new handle to the same key indicated by the <i>hKey</i>
parameter.</p><p>If <i>lpSubKey</i> is set to NULL by the client, the server
MUST fail this method and return ERROR_INVALID_PARAMETER.</p><p>Next, the server checks if the KEY_WOW64_32KEY is set in the
<i>samDesired</i> parameter. If the KEY_WOW64_32KEY is set in the <i>samDesired</i>
parameter, the server MUST create the key in the 32-bit key namespace (KEYS32).
If the KEY_WOW64_32KEY is not set in the <i>samDesired</i> parameter, the
server MUST create the key in the 64-bit key namespace (KEYS64).</p><p>Next, the server MUST determine if the key path indicated by
<i>hKey</i> and <i>lpSubKey</i> refer to a path that is within the subset of
registry paths that can support both 64-bit and 32-bit key namespaces (section
3.1.1.4). If the key path indicated by <i>hKey</i> and <i>lpSubKey</i> are
within the subset of registry paths that can support both 64-bit and 32-bit key
namespaces, the server MUST open the registry key within the appropriate path
in the 64-bit key namespace. For example, if <i>hKey</i> refers to
HKEY_LOCAL_MACHINE\Software and the value of the <i>lpSubKey</i> parameter is
&#34;TEST_KEY&#34; and the server MUST operate on the 32-bit key namespace,
then the server MUST open the HKEY_LOCAL_MACHINE\Software\Wow6432Node\TEST_KEY
key.</p><p>The server MUST first validate that the key specified by <i>lpSubKey</i>
is a child key of the key specified by <i>hKey</i>. If the key specified by <i>lpSubKey</i>
is not a subkey of the key specified by <i>hKey</i>, the server MUST set <i>phkResult</i>
to NULL and return ERROR_FILE_NOT_FOUND.</p><p>If the <i>dwOptions</i> parameter specifies the
REG_OPTION_BACKUP_RESTORE option, the server MUST ignore all bits set in the <i>samDesired</i>
parameter except for KEY_WOW64_32KEY and KEY_WOW64_64KEY. The desired key
access MUST be computed based on whether the caller holds the backup and
restore privileges as outlined in the following table. If the caller holds
neither privilege, the server MUST fail the method and return
STATUS_ACCESS_DENIED.</p><table><thead>
  <tr>
   <th>
   <p>Privileges Held</p>
   </th>
   <th>
   <p>Desired Access</p>
   </th>
  </tr>
 </thead><tbody><tr>
  <td>Backup and Restore</td>
  <td>STANDARD_RIGHTS_READ KEY_QUERY_VALUE KEY_ENUMERATE_SUB_KEYS KEY_NOTIFY STANDARD_RIGHTS_WRITE KEY_SET_VALUE KEY_CREATE_SUB_KEY ACCESS_SYSTEM_SECURITY WRITE_DAC WRITE_OWNER DELETE</td>
 </tr><tr>
  <td>Only Backup</td>
  <td>STANDARD_RIGHTS_READ KEY_QUERY_VALUE KEY_ENUMERATE_SUB_KEYS KEY_NOTIFY ACCESS_SYSTEM_SECURITY</td>
 </tr><tr>
  <td>Only Restore</td>
  <td>STANDARD_RIGHTS_WRITE KEY_SET_VALUE KEY_CREATE_SUB_KEY ACCESS_SYSTEM_SECURITY WRITE_DAC WRITE_OWNER DELETE</td>
 </tr></tbody></table><p>The server MUST validate that the client has access to open
the key using the security descriptor of the key indicated by <i>lpSubKey</i>.
If the value of <i>samDesired</i> includes flags set that are not listed in
section 2.2.3, the server MUST return ERROR_INVALID_PARAMETER.</p><p>If the caller is permitted to open the key, the server MUST
return 0 to indicate success, create a new valid context handle, insert it into
the handle table (HANDLETABLE), and place the handle value (see <a href="93d384ce-c668-4f48-a5f7-a633bc042a29" data-linktype="relative-path">3.1.1.9</a>) in the <i>phkResult</i>
parameter. If the caller does not have access, the server MUST return
ERROR_ACCESS_DENIED.</p><p>The server MUST return 0 to indicate success or an
appropriate error code (as specified in [MS-ERREF] section 2.2 or error codes
specified in section <a href="53c0a480-f1c8-493e-abf8-6bb4de4d95eb" data-linktype="relative-path">2.2.6</a>)
to indicate an error.</p></div>