ZwFlushKey function

The ZwFlushKey routine forces a registry key to be committed to disk.


  HANDLE KeyHandle



Handle to the registry key to be flushed to disk. This handle is created by a successful call to ZwCreateKey or ZwOpenKey.

Return Value

ZwFlushKey returns STATUS_SUCCESS if the key information was transferred to disk, or the appropriate error code on failure.


You can flush changes made by ZwCreateKey or ZwSetValueKey by calling ZwFlushKey. This routine does not return until all the changed data that is associated with KeyHandle has been written to disk. ZwFlushKey flushes the entire registry hive for the key, which includes every subkey of the key specified.

Note   This routine can flush the entire registry. Accordingly, it can generate a great deal of I/O. Since the system flushes key changes automatically every few seconds, you seldom need to call ZwFlushKey.
For more information about working with registry keys, see Using the Registry in a Driver.
Note  If the call to this function occurs in user mode, you should use the name "NtFlushKey" instead of "ZwFlushKey".
For calls from kernel-mode drivers, the NtXxx and ZwXxx versions of a Windows Native System Services routine can behave differently in the way that they handle and interpret input parameters. For more information about the relationship between the NtXxx and ZwXxx versions of a routine, see Using Nt and Zw Versions of the Native System Services Routines.


Minimum supported client Available in Windows 2000 and later versions of Windows.
Target Platform Universal
Header wdm.h (include Wdm.h, Ntddk.h, Ntifs.h)
Library NtosKrnl.lib
DLL NtosKrnl.exe
DDI compliance rules IrqlZwPassive, ZwRegistryCreate, ZwRegistryOpen, HwStorPortProhibitedDDIs, ZwRegistryCreate(storport), ZwRegistryOpen(storport)

See Also

Using Nt and Zw Versions of the Native System Services Routines