Click to Rate and Give Feedback
MSDN
MSDN Library
System Services
Registry
Registry Reference
Registry Functions
 RegCloseKey Function
RegCloseKey Function

Closes a handle to the specified registry key.

Syntax

LONG WINAPI RegCloseKey(
  __in  HKEY hKey
);

Parameters

hKey [in]

A handle to the open key to be closed. The handle must have been opened by the RegCreateKeyEx, RegCreateKeyTransacted, RegOpenKeyEx, RegOpenKeyTransacted, or RegConnectRegistry function.

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

The handle for a specified key should not be used after it has been closed, because it will no longer be valid. Key handles should not be left open any longer than necessary.

The RegCloseKey function does not necessarily write information to the registry before returning; it can take as much as several seconds for the cache to be flushed to the hard disk. If an application must explicitly write registry information to the hard disk, it can use the RegFlushKey function. RegFlushKey, however, uses many system resources and should be called only when necessary.

Examples

For an example, see Deleting a Key with Subkeys.

Requirements

Client Requires Windows Vista, Windows XP, or Windows 2000 Professional.
Server Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
Header

Declared in Winreg.h; include Windows.h.

Library

Use Advapi32.lib.

DLL

Requires Advapi32.dll.

See Also

RegConnectRegistry
RegCreateKeyEx
RegDeleteKey
RegFlushKey
Registry Functions
Registry Overview
RegOpenKeyEx


Send comments about this topic to Microsoft

Build date: 8/14/2008

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker