SetEntriesInAcl - Error 87

C

ChrisWoodruff

I have code from VB6 to apply permissions (folders, regkeys, whatever).
I need to use it in a .NET 2003 project I'm working on.

So after the conversion wizard ran on the code I made some tweaks to the
declare statements to get things to work. At this point it works up
until the call to SetEntriesInAcl. This adds the ACE to the DACL as
needed. The code below is not "complete" (trying to get this relatively
short) - if it IS needed I can definately provide it.

Anyway, the API returns 87 - "Invalid/Incorrect Parameter". I would
"assume" that it is referring to EXPLICIT_ACCESS structure. According to
MSDN the API is actually looking for a pointer to an EXPLICIT_ACCESS
array, however another MSDN article showed this code (more or less) for
VB6 and using it in this way.

Any help is appreciated.
Thanks,
Chris


Private Structure TRUSTEE
Dim pMultipleTrustee As Integer
Dim MultipleTrusteeOperation As Integer
Dim TrusteeForm As Integer
Dim TrusteeType As Integer
Dim ptstrName As String
End Structure

Private Structure EXPLICIT_ACCESS
Dim grfAccessPermissions As Integer
Dim grfAccessMode As Integer
Dim grfInheritance As Integer
Dim pTRUSTEE As TRUSTEE
End Structure

Private Declare Function SetEntriesInAcl _
Lib "Advapi32.dll" Alias "SetEntriesInAclA" _
(ByVal CountofExplicitEntries As Integer, _
ByRef ea As EXPLICIT_ACCESS, _
ByVal OldAcl As Integer, _
ByRef NewAcl As Integer) As Integer

Private Sub PartialPermCode()

Dim lngResult = Integer

lngResult = GetNamedSecurityInfo(strObject, udtObjectType, _
DACL_SECURITY_INFORMATION, 0, 0, pOldDACL, 0, pSecDesc)

If lngresult = ERROR_SUCCESS Then
BuildExplicitAccessWithName(ea, strAccount, udtType, SET_ACCESS, _
CONTAINER_INHERIT_ACE Or OBJECT_INHERIT_ACE)

lngResult = SetEntriesInAcl(1, ea, pOldDACL, pNewDACL)

If lngResult = ERROR_SUCCESS Then
lngResult = SetNamedSecurityInfo(strObject, udtObjectType, _
DACL_SECURITY_INFORMATION, 0, 0, pNewDACL, 0)
End If
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top