RegSetKeySecurity function

The RegSetKeySecurity function sets the security of an open registry key.

Syntax

LSTATUS RegSetKeySecurity(
  HKEY                 hKey,
  SECURITY_INFORMATION SecurityInformation,
  PSECURITY_DESCRIPTOR pSecurityDescriptor
);

Parameters

hKey

A handle to an open key for which the security descriptor is set.

SecurityInformation

A set of bit flags that indicate the type of security information to set. This parameter can be a combination of the SECURITY_INFORMATION bit flags.

pSecurityDescriptor

A pointer to a SECURITY_DESCRIPTOR structure that specifies the security attributes to set for the specified key.

Return Value

If the function succeeds, the function returns ERROR_SUCCESS.

If the function fails, it returns 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

If hKey is one of the predefined keys, use the RegCloseKey function to close the predefined key to ensure that the new security information is in effect the next time the predefined key is referenced.

Requirements

   
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header winreg.h (include Windows.h)
Library Advapi32.lib
DLL Advapi32.dll

See Also

FormatMessage

Low-level Access Control

Low-level Access Control Functions

RegCloseKey

RegDeleteKey

RegGetKeySecurity

SECURITY_DESCRIPTOR

SECURITY_INFORMATION