RegFlushKey Function

The RegFlushKey function flushes any changes to a specified registry key into the specified registry hive.


LSTATUS RegFlushKey(
  HKEY hKey
);
                

Parameters

hKey
A handle to an open registry key. The handle must have been opened with the KEY_WRITE access right. This parameter can be a handle to one of the following pre-defined keys:
  • HKEY_CLASSES_ROOT
  • HKEY_CURRENT_CONFIG
  • HKEY_CURRENT_USER
  • HKEY_LOCAL_MACHINE
  • HKEY_USERS

Return Value

Success: If the function succeeds, the return value is ERROR_SUCCESS.

Failure: If the function fails, the return value is a non-zero error code defined in WinError.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a textual description of the error.

Remarks

When changes are made to the registry, they are written to a file in memory. The RegFlushKey function ensures that these changes are written to the registry hive file on disk.

For HKEY_LOCAL_MACHINE and HKEY_USERS, the system automatically flushes changes to disk periodically. Therefore, explicit calls to RegFlushKey for these keys are usually not necessary.

However, if an application makes critical changes to HKEY_LOCAL_MACHINE or HKEY_USERS and needs to ensure that these changes are immediately persisted to disk, it can call RegFlushKey. Note that flushing the registry can be a time-consuming operation.

It is generally recommended to close registry keys using RegCloseKey when they are no longer needed, rather than relying solely on flushing.

Requirements

Minimum supported client: Windows 2000 Professional

Minimum supported server: Windows 2000 Server

Header: winreg.h (include Windows.h)

Library: Advapi32.lib

DLL: Advapi32.dll

See Also