Platform SDK: Access Control

SetFileSecurity

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

Windows NT 4.0 and later: You can use the SetNamedSecurityInfo function.

BOOL SetFileSecurity(
  LPCTSTR lpFileName,                       // file name
  SECURITY_INFORMATION SecurityInformation, // contents
  PSECURITY_DESCRIPTOR pSecurityDescriptor  // SD
);

Parameters

lpFileName
[in] Pointer to a null-terminated string specifying the file or directory for which security is set. Note that security applied to a directory is not inherited by its children.
SecurityInformation
[in] Specifies a SECURITY_INFORMATION structure identifying the contents of the security descriptor pointed to by the pSecurityDescriptor parameter.
pSecurityDescriptor
[in] Pointer to a SECURITY_DESCRIPTOR structure.

Return Values

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

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

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Header: Declared in Winbase.h; include Windows.h.
  Library: Use Advapi32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.

See Also

Low-Level Access-Control Overview, Low-Level Access Control Functions, GetFileSecurity, SECURITY_DESCRIPTOR, SECURITY_INFORMATION, SetKernelObjectSecurity, SetPrivateObjectSecurity, SetUserObjectSecurity