Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than advapi32, prefix the name with the module name and a period.
Declare Function SetNamedSecurityInfo Lib "advapi32.dll" ( _
ByVal pObjectName As String, _
ByVal ObjectType As SE_OBJECT_TYPE, _
ByVal SecurityInfo As SECURITY_INFORMATION, _
ByVal psidOwner As IntPtr, _
ByVal psidGroup As IntPtr, _
ByVal pDacl As IntPtr, _
ByVal pSacl As IntPtr) As Integer
Dim pSecDesc, pNewDACL, pOldDACL As IntPtr
Dim ea As EXPLICIT_ACCESS
Dim Win32Error As Win32Exception
Dim ret As Integer
' merge this Explict Access with the existing DACL
ret = SetEntriesInAcl(1, ea, pOldDACL, pNewDACL)
If ret <> 0 Then
Win32Error = New Win32Exception(ret)
Throw New Exception(Win32Error.Message)
End If
' write the new Security Descriptor/DACL back
ret = SetNamedSecurityInfo(strPath, _
SE_OBJECT_TYPE.SE_FILE_OBJECT, _
SECURITY_INFORMATION.DACL_SECURITY_INFORMATION, _
Nothing, Nothing, pNewDACL, Nothing)
If ret <> 0 Then
Win32Error = New Win32Exception(ret)
Throw New Exception(Win32Error.Message)
End If
public static void SetFileOrFolderOwner(String objectName) //Note this is very basic and is silent on fail as I havent checked GetlastError and thrown an exception etc
{
IntPtr sidPtr = IntPtr.Zero;
SECURITY_INFORMATION sFlags = SECURITY_INFORMATION.Owner;
System.Security.Principal.NTAccount user = new System.Security.Principal.NTAccount("P1R4T3\\Harris");
System.Security.Principal.SecurityIdentifier sid = (System.Security.Principal.SecurityIdentifier) user.Translate(typeof (System.Security.Principal.SecurityIdentifier));
//Probably should release the IntPtr here to avoid memory leakage?????
}
VB.Net Sample Code:
Dim pSecDesc, pNewDACL, pOldDACL As IntPtr
Dim ea As EXPLICIT_ACCESS
Dim Win32Error As Win32Exception
Dim ret As Integer
' merge this Explict Access with the existing DACL
ret = SetEntriesInAcl(1, ea, pOldDACL, pNewDACL)
If ret <> 0 Then
Win32Error = New Win32Exception(ret)
Throw New Exception(Win32Error.Message)
End If
' write the new Security Descriptor/DACL back
ret = SetNamedSecurityInfo(strPath, _
SE_OBJECT_TYPE.SE_FILE_OBJECT, _
SECURITY_INFORMATION.DACL_SECURITY_INFORMATION, _
Nothing, Nothing, pNewDACL, Nothing)
If ret <> 0 Then
Win32Error = New Win32Exception(ret)
Throw New Exception(Win32Error.Message)
End If
Alternative Managed API:
Do you know one? Please contribute it!
The SetNamedSecurityInfo function sets specified security information in the security descriptor of a specified object. The caller identifies the object by name
1/6/2010 7:34:28 AM - anfortas.geo@yahoo.com-216.204.61.86
Indicates a type of object that supports security when calling functions such as GetSecurityInfo and SetSecurityInfo.
3/16/2007 7:43:11 AM - -80.212.75.179
Identifies the object-related security information to be set by SetNamedSecurityInfo
2/7/2014 3:57:04 PM - -202.1.96.195
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).