SetFileSecurity function
Applies to: desktop apps only
The SetFileSecurity function sets the security of a file or directory object.
This function is obsolete. Use the SetNamedSecurityInfo function instead.
Syntax
BOOL WINAPI SetFileSecurity( __in LPCTSTR lpFileName, __in SECURITY_INFORMATION SecurityInformation, __in PSECURITY_DESCRIPTOR pSecurityDescriptor );
Parameters
- lpFileName [in]
-
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 [in]
-
Specifies a SECURITY_INFORMATION structure that identifies the contents of the security descriptor pointed to by the pSecurityDescriptor parameter.
- pSecurityDescriptor [in]
-
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
|
Minimum supported client | Windows XP |
|---|---|
|
Minimum supported server | Windows Server 2003 |
|
Header |
|
|
Library |
|
|
DLL |
|
|
Unicode and ANSI names | SetFileSecurityW (Unicode) and SetFileSecurityA (ANSI) |
See also
- Low-level Access Control
- Low-level Access Control Functions
- GetFileSecurity
- SECURITY_DESCRIPTOR
- SECURITY_INFORMATION
- SetKernelObjectSecurity
- SetNamedSecurityInfo
- SetPrivateObjectSecurity
- SetUserObjectSecurity
Send comments about this topic to Microsoft
Build date: 3/7/2012
The SetFileSecurity function may fail with the following error codes:
- ERROR_INVALID_OWNER
- The calling user tries to assign the ownership of the file to a SID other than his own identity, which doesn't work, since a user cannot un-own files. This action must be performed by the user who will be the new owner. For details, see KB245153.
- 8/9/2008
- Roland Illig
- 8/9/2008
- Roland Illig