SetFileSecurityA function

The SetFileSecurity function sets the security of a file or directory object.

This function is obsolete. Use the SetNamedSecurityInfo function instead.

Syntax

BOOL SetFileSecurityA(
  LPCSTR               lpFileName,
  SECURITY_INFORMATION SecurityInformation,
  PSECURITY_DESCRIPTOR pSecurityDescriptor
);

Parameters

lpFileName

A pointer to a null-terminated string that specifies the file or directory for which security is set. Note that security applied to a directory is not inherited by its children.

SecurityInformation

Specifies a SECURITY_INFORMATION structure that identifies the contents of the security descriptor pointed to by the pSecurityDescriptor parameter.

pSecurityDescriptor

A pointer to a SECURITY_DESCRIPTOR structure.

Return Value

If the function succeeds, the function returns nonzero.

If the function fails, it returns zero. To get extended error information, call GetLastError.

Remarks

The SetFileSecurity function is successful only if the following conditions are met:

  • If the owner of the object is being set, the calling process must have either WRITE_OWNER permission or be the owner of the object.
  • If the discretionary access control list (DACL) of the object is being set, the calling process must have either WRITE_DAC permission or be the owner of the object.
  • If the system access control list (SACL) of the object is being set, the SE_SECURITY_NAME privilege must be enabled for the calling process.

Requirements

   
Windows version Windows XP [desktop apps only] Windows Server 2003 [desktop apps only]
Target Platform Windows
Header winbase.h (include Windows.h)
Library Advapi32.lib
DLL Advapi32.dll

See Also

GetFileSecurity

Low-level Access Control

Low-level Access Control Functions

SECURITY_DESCRIPTOR

SECURITY_INFORMATION

SetKernelObjectSecurity

SetNamedSecurityInfo

SetPrivateObjectSecurity

SetUserObjectSecurity