Registry Functions
RegCloseKey
LONG RegCloseKey(HKEY hKey);
Parameters
hKey
[in] A handle to the open key to be closed.
Return Value
If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage
function with the FORMAT_MESSAGE_FROM_SYSTEM
flag to get a generic description of the error.
Remarks
Closing a handle to a key does not remove the key or its values from the registry. All the information associated with the key is maintained until it is explicitly deleted. If the key was opened with RegSaveKey
, closing the key flushes any buffered changes to the disk.
RegCreateKeyEx
LONG RegCreateKeyEx(HKEY hKey, LPCTSTR lpSubKey, DWORD Reserved, LPTSTR lpClass, DWORD dwOptions, REGSAM samDesired, LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition);
Parameters
hKey
[in] A handle to an open key in the registry.lpSubKey
[in] The name of the registry subkey to be created or opened.Reserved
[in] This parameter is reserved and must be zero.lpClass
[in, optional] A null-terminated string that specifies the class of the specified key. This parameter may be NULL.dwOptions
[in] Specifies options for the key.samDesired
[in] A mask that specifies the access rights for the key to be created.lpSecurityAttributes
[in, optional] A pointer to aSECURITY_ATTRIBUTES
structure that specifies the security attributes of the new key.phkResult
[out] A pointer to a variable that receives a handle to the created or opened key.lpdwDisposition
[out, optional] A pointer to a variable that receives a value indicating whether the key was created or opened.
Return Value
If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a nonzero error code.
Remarks
This function creates a new key or opens an existing one. If the key already exists, the function opens it. The function will create the key if it does not exist.
RegDeleteKey
LONG RegDeleteKey(HKEY hKey, LPCTSTR lpSubKey);
Parameters
hKey
[in] A handle to an open key in the registry.lpSubKey
[in] The name of the subkey to be deleted.
Return Value
If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a nonzero error code.
Remarks
This function deletes a subkey and all its descendants from the registry. It can only delete keys that have no subkeys.
RegDeleteValue
LONG RegDeleteValue(HKEY hKey, LPCTSTR lpValueName);
Parameters
hKey
[in] A handle to an open key in the registry.lpValueName
[in, optional] The name of the value to be deleted.
Return Value
If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a nonzero error code.
Remarks
This function deletes a specific value entry from the registry.
RegEnumKeyEx
LONG RegEnumKeyEx(HKEY hKey, DWORD dwIndex, LPTSTR lpName, LPDWORD lpcchName, LPDWORD lpReserved, LPTSTR lpClass, LPDWORD lpcchClass, PFILETIME lpftLastWriteTime);
Parameters
hKey
[in] A handle to an open key whose subkeys are to be enumerated.dwIndex
[in] The index of the subkey to retrieve.lpName
[out, optional] A buffer that receives the name of the subkey.lpcchName
[in, out, optional] The size in TCHARs of the buffer pointed to bylpName
.lpReserved
[in] This parameter is reserved and must be NULL.lpClass
[out, optional] A buffer that receives the class of the subkey.lpcchClass
[in, out, optional] The size in TCHARs of the buffer pointed to bylpClass
.lpftLastWriteTime
[out, optional] A pointer to aFILETIME
structure that receives the date and time that the subkey was last modified.
Return Value
If the function succeeds, the return value is ERROR_SUCCESS. If the subkey has no more subkeys to be enumerated, the return value is ERROR_NO_MORE_ITEMS. If the function fails, the return value is a nonzero error code.
Remarks
This function enumerates the subkeys of the specified key.
RegEnumValue
LONG RegEnumValue(HKEY hKey, DWORD dwIndex, LPTSTR lpValueName, LPDWORD lpcchValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData);
Parameters
hKey
[in] A handle to an open key whose values are to be enumerated.dwIndex
[in] The index of the value to retrieve.lpValueName
[out, optional] A pointer to a buffer that receives a copy of the name of the value.lpcchValueName
[in, out, optional] The size in TCHARs of the buffer pointed to bylpValueName
.lpReserved
[in] Reserved for future use. Must be NULL.lpType
[out, optional] A pointer to a variable that receives the data type of the value.lpData
[out, optional] A pointer to a buffer that receives a copy of the data for the value.lpcbData
[in, out, optional] A pointer to a variable that specifies the size in bytes of the buffer pointed to bylpData
.
Return Value
If the function succeeds, the return value is ERROR_SUCCESS. If there are no more values to be enumerated, the return value is ERROR_NO_MORE_ITEMS. If the function fails, the return value is a nonzero error code.
Remarks
This function enumerates the values of the specified key.
RegFlushKey
LONG RegFlushKey(HKEY hKey);
Parameters
hKey
[in] A handle to an open key.
Return Value
If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a nonzero error code.
Remarks
This function writes all buffered information for the specified key and all its subkeys to disk.
RegOpenKeyEx
LONG RegOpenKeyEx(HKEY hKey, LPCTSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult);
Parameters
hKey
[in] A handle to an open key in the registry.lpSubKey
[in] The name of the registry subkey to be opened.ulOptions
[in] This parameter is reserved and must be zero.samDesired
[in] A mask that specifies the desired access rights to the key.phkResult
[out] A pointer to a variable that receives a handle to the opened key.
Return Value
If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a nonzero error code.
Remarks
This function opens an existing subkey and returns a handle to it.
RegQueryInfoKey
LONG RegQueryInfoKey(HKEY hKey, LPTSTR lpClass, LPDWORD lpcchClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcchMaxSubKeyLen, LPDWORD lpcchMaxClassLen, LPDWORD lpcValues, LPDWORD lpcchMaxValueNameLen, LPDWORD lpcchMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime);
Parameters
hKey
[in] A handle to an open key in the registry.lpClass
[out, optional] Pointer to a buffer that receives the class of the key.lpcchClass
[in, out, optional] Size of the buffer pointed to bylpClass
.lpReserved
[in] Reserved; must be NULL.lpcSubKeys
[out, optional] Pointer to a variable that receives the number of subkeys.lpcchMaxSubKeyLen
[out, optional] Pointer to a variable that receives the size of the largest subkey name.lpcchMaxClassLen
[out, optional] Pointer to a variable that receives the size of the largest class name.lpcValues
[out, optional] Pointer to a variable that receives the number of value entries associated with the key.lpcchMaxValueNameLen
[out, optional] Pointer to a variable that receives the size of the largest value name.lpcchMaxValueLen
[out, optional] Pointer to a variable that receives the size of the largest data.lpcbSecurityDescriptor
[out, optional] Pointer to a variable that receives the size of the security descriptor.lpftLastWriteTime
[out, optional] Pointer to aFILETIME
structure that receives the date and time the key was last modified.
Return Value
If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a nonzero error code.
Remarks
This function retrieves information about a specified key.
RegQueryValueEx
LONG RegQueryValueEx(HKEY hKey, LPCTSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData);
Parameters
hKey
[in] A handle to an open key in the registry.lpValueName
[in, optional] The name of the value entry to query.lpReserved
[in] Reserved for future use. Must be NULL.lpType
[out, optional] A pointer to a variable that receives the data type of the value.lpData
[out, optional] A pointer to a buffer that receives the data for the value.lpcbData
[in, out, optional] A pointer to a variable that specifies the size in bytes of the buffer pointed to bylpData
.
Return Value
If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a nonzero error code.
Remarks
This function copies (or retrieves) the data for a specified value name into a buffer.
RegSetValueEx
LONG RegSetValueEx(HKEY hKey, LPCTSTR lpValueName, DWORD Reserved, DWORD dwType, const BYTE* lpData, DWORD cbData);
Parameters
hKey
[in] A handle to an open key in the registry.lpValueName
[in, optional] The name of the value to be set.Reserved
[in] Reserved for future use. Must be zero.dwType
[in] The data type of the data to be stored in the given value.lpData
[in] Pointer to the buffer that contains the data to be stored.cbData
[in] Size, in bytes, of the data pointed to by thelpData
parameter.
Return Value
If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a nonzero error code.
Remarks
This function creates a new value entry or overwrites an existing value entry for the specified key.