RegSetKeySecurity function (winreg.h)

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

Syntax

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

Parameters

[in] hKey

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

[in] 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.

[in] 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

Requirement Value
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