4.3 Detailed Example
This section provides a more detailed example of reading a registry key and value.
The client receives a request from an application, such as Regedit.exe, to open the root key HKEY_LOCAL_MACHINE on the server for reading.
After establishing a connection to the server, the client sends an OpenLocalMachine method that has the following values for the parameters.
ServerName = 0 samDesired = 0x00000001 phKey = NULL
When the server receives this request from the client, the server opens the handle to the root key HKEY_LOCAL_MACHINE with read access, and returns 0 (ERROR_SUCCESS) and the pointer to the opened handle in the phKey parameter of the response.
The client then uses the handle that is returned in phKey to operate on HKEY_LOCAL_MACHINE. For example, to open a subkey "SYSTEM" for read access, the client sends a BaseRegOpenKey method that has the following values for the parameters.
hKey = Handle returned in the phKey parameter of the previous server response. lpSubKey = "SYSTEM\0" dwOptions = 0 samDesired = 0x00000001 phkResult = NULL
When the server receives this request from the client, it opens the handle to the key HKEY_LOCAL_MACHINE \SYSTEM with read access, and returns 0 (ERROR_SUCCESS) and the pointer to the opened handle in the phkResult parameter of the response.
When the client is finished operating on the key HKEY_LOCAL_MACHINE \SYSTEM, it closes the handle to this key by sending a BaseRegCloseKey method that has the following value for the parameter.
hkey = Handle returned in the phkResult parameter of the previous server response.
When the server receives this request from the client, it closes the handle to the key HKEY_LOCAL_MACHINE \SYSTEM and returns 0 (ERROR_SUCCESS).