I am getting the error "The security ID structure is invalid." When running
this code.
Sub SetPermissions(ByRef vPath As String, ByVal UserName As String)
Dim objADsSec As ADsSecurity
Dim objSecDes As SecurityDescriptor
Dim objDAcl As AccessControlList
Dim objAce As Object
Dim objAce1 As AccessControlEntry
Dim objAce2 As AccessControlEntry
Dim objSId As ADsSID
Dim objSIdHex As Object
UserName = "molnarc"
objADsSec = New ADsSecurity
objSecDes = CType(objADsSec.GetSecurityDescriptor("FILE://" &
vPath), SecurityDescriptor)
objDAcl = CType(objSecDes.DiscretionaryAcl, AccessControlList)
objSId = New ADsSID
objSId.SetAs(ADSSECURITYLib.ADS_SID_FORMAT.ADS_SID _SAM,
CStr(UserName))
objSIdHex = objSId.GetAs(ADSSECURITYLib.ADS_SID_FORMAT.ADS_SID _SDDL)
' Add a new objAce so that the User has Full Control on NTFS Files.
objAce1 = New AccessControlEntry
objAce1.Trustee = CStr(objSIdHex)
objAce1.AccessMask = ActiveDs.ADS_RIGHTS_ENUM.ADS_RIGHT_GENERIC_ALL
objAce1.AceType = ActiveDs.ADS_ACETYPE_ENUM.ADS_ACETYPE_ACCESS_ALLOW ED
objAce1.AceFlags = ActiveDs.ADS_ACEFLAG_ENUM.ADS_ACEFLAG_INHERIT_ACE
Or ActiveDs.ADS_ACEFLAG_ENUM.ADS_ACEFLAG_INHERIT_ONLY _ACE Or 1
objDAcl.AddAce(objAce1)
' Add a new objAce so that the User has Full Control on NTFS Folders.
objAce2 = New AccessControlEntry
objAce2.Trustee = CStr(objSIdHex)
objAce2.AccessMask = ActiveDs.ADS_RIGHTS_ENUM.ADS_RIGHT_GENERIC_ALL
objAce2.AceType = ActiveDs.ADS_ACETYPE_ENUM.ADS_ACETYPE_ACCESS_ALLOW ED
objAce2.AceFlags = ActiveDs.ADS_ACEFLAG_ENUM.ADS_ACEFLAG_INHERIT_ACE
Or 1
objDAcl.AddAce(objAce2)
objSecDes.DiscretionaryAcl = objDAcl
' Set Permissions on the NTFS folder.
objADsSec.SetSecurityDescriptor(objSecDes) '<-- Error happens here
End Sub
I have even tried this and still get the error.
Sub SetPermissions(ByRef vPath As String, ByVal UserName As String)
Dim objADsSec As ADsSecurity
Dim objSecDes As SecurityDescriptor
Dim objDAcl As AccessControlList
Dim objAce As Object
Dim objAce1 As AccessControlEntry
Dim objAce2 As AccessControlEntry
Dim objSId As ADsSID
Dim objSIdHex As Object
UserName = "molnarc"
objADsSec = New ADsSecurity
objSecDes = CType(objADsSec.GetSecurityDescriptor("FILE://" &
vPath), SecurityDescriptor)
objADsSec.SetSecurityDescriptor(objSecDes) '<-- Error happens here
end sub
Any clue as what i could be doing wrong?