Results 1 to 2 of 2

Thread: [RESOLVED] ADOX.GetPermissions Mystery - Help!

  1. #1

    Thread Starter
    Hyperactive Member rjbudz's Avatar
    Join Date
    Jul 2005
    Location
    San Diego
    Posts
    262

    Resolved [RESOLVED] ADOX.GetPermissions Mystery - Help!

    I must be missing something, because this issue is not addressed anywhere and it seems to be a significant omission:

    I'm attempting to get the permissions of all my users for all the objects within a database (with a networked system.mdw), using VBA so I can export it to Excel to play with.

    I can get all user names, all groups, all forms, tables, etc. so it's just a matter of looping through everything to get what I want. As a trial run I hard coded the user group, object name and object type in GetPermissions within a Function.

    The problem arises with the function's return value.
    The answer I get is: 147456

    What does this mean? Please don't tell me "What is life, the universe and everything?" though I wouldn't be overly surprised.

    Microsoft has the GetPermissions fuction being fed into a function called ‘DecodePerms()’ which is all well and good if they had that code as well, which they don't.

    Here is the pertinent code from Microsoft:
    VB Code:
    1. Set catDB = New ADOX.Catalog
    2.  
    3. With catDB
    4.    ' Open Catalog object by using connection to current database.
    5.    .ActiveConnection = CurrentProject.Connection
    6.    
    7. ( ...)
    8.  
    9.    ' Retrieve current permissions and display them in the Immediate window.
    10.    lngRightsNow = .Groups(strGroup).GetPermissions(varObjName, lngObjectType, _
    11.       varObjectID)
    12.    Debug.Print [COLOR=Red]DecodePerms[/COLOR](lngRightsNow)
    13. End With
    It seems kind of dumb to spend the time to create an explanation if it leaves out the most important part, don’t ya think?

    Someone must have used the GetPermissions method at some point in history and survived to write about it.

    Any help out there?

  2. #2

    Thread Starter
    Hyperactive Member rjbudz's Avatar
    Join Date
    Jul 2005
    Location
    San Diego
    Posts
    262

    Re: ADOX.GetPermissions Mystery - Help!

    Well, I guess not!

    I got the answer from another discussion board. For the sake of anyone else who may need to know this, here it is (from http://www.microsoft.com/office/comm...xp=&sloc=en-us):

    Well ... if you look in the help topic for the GetPermissions method in
    the ADOX help file, you'll see that the method "Returns a Long value
    that specifies a bitmask containing the permissions that the group or
    user has on the object. This value can be one or more of the RightsEnum
    constants." And if you click through to the topic on RightsEnum, you'll
    see a table that I'll try to reproduce readably below:

    Constant / Value / Description
    ==============================
    adRightCreate / 16384 (&H4000) / The user or group has permission to
    create new objects of this type.

    adRightDelete / 65536 (&H10000) / The user or group has permission to
    delete data from an object. For objects such as Tables, the user has
    permission to delete data values from records.

    adRightDrop / 256 (&H100) / The user or group has permission to remove
    objects from the catalog. For example, Tables can be deleted by a DROP
    TABLE SQL command.

    adRightExclusive / 512 (&H200) / The user or group has permission to
    access the object exclusively.

    adRightExecute / 536870912 (&H20000000) / The user or group has
    permission to execute the object.

    adRightFull / 268435456 (&H10000000) / The user or group has all
    permissions on the object.

    adRightInsert / 32768 (&H8000) / The user or group has permission to
    insert the object. For objects such as Tables, the user has permission
    to insert data into the table.

    adRightMaximumAllowed / 33554432 (&H2000000) / The user or group has the
    maximum number of permissions allowed by the provider. Specific
    permissions are provider-dependent.

    adRightNone / 0 / The user or group has no permissions for the object.

    adRightRead / -2147483648 (&H80000000) / The user or group has
    permission to read the object. For objects such as Tables, the user has
    permission to read the data in the table.

    adRightReadDesign / 1024 (&H400) / The user or group has permission to
    read the design for the object.

    adRightReadPermissions / 131072 (&H20000) / The user or group can view,
    but not change, the specific permissions for an object in the catalog.

    adRightReference / 8192 (&H2000) / The user or group has permission to
    reference the object.

    adRightUpdate / 1073741824 (&H40000000) / The user or group has
    permission to update the object. For objects such as Tables, the user
    has permission to update the data in the table.

    adRightWithGrant / 4096 (&H1000) / The user or group has permission to
    grant permissions on the object.

    adRightWriteDesign / 2048 (&H800) / The user or group has permission to
    modify the design for the object.

    adRightWriteOwner / 524288 (&H80000) / The user or group has permission
    to modify the owner of the object.

    adRightWritePermissions / 262144 (&H40000) / The user or group can
    modify the specific permissions for an object in the catalog.
    ==============================

    The permissions are combined by "ORing" them, and you can check for each
    permission value by ANDing it to the combined permissions and seeing if
    the result is nonzero. So, what does 147456 mean? Let's see, in
    hexadecimal that would be &H24000, which is equivalent to

    &H20000 (adRightReadPermissions)
    OR
    &H4000 (adRightCreate)

    So the group has permissions to create objects of this type, as well as
    to read permissions for this object.

    If you understand how that works, you should be able to create your own
    DecodePerms() function.

    --
    Dirk Goldgar, MS Access MVP
    www.datagnostics.com



    To make it even easier:

    VB Code:
    1. Function DecodePerms(Permissions As Long) As String
    2. ' returns a comma delimited string of permissions
    3.  
    4.     DecodePerms = ""
    5.    
    6.     If (adRightRead And Permissions) Then DecodePerms = DecodePerms & "Read" & ","
    7.     If (adRightNone And Permissions) Then DecodePerms = DecodePerms & "None" & ","
    8.     If (adRightDrop And Permissions) Then DecodePerms = DecodePerms & "Drop" & ","
    9.     If (adRightExclusive And Permissions) Then DecodePerms = DecodePerms & "Exclusive" & ","
    10.     If (adRightReadDesign And Permissions) Then DecodePerms = DecodePerms & "Read Design" & ","
    11.     If (adRightWriteDesign And Permissions) Then DecodePerms = DecodePerms & "Write Design" & ","
    12.     If (adRightWithGrant And Permissions) Then DecodePerms = DecodePerms & "With Grant" & ","
    13.     If (adRightReference And Permissions) Then DecodePerms = DecodePerms & "Reference" & ","
    14.     If (adRightCreate And Permissions) Then DecodePerms = DecodePerms & "Create" & ","
    15.     If (adRightInsert And Permissions) Then DecodePerms = DecodePerms & "Insert" & ","
    16.     If (adRightDelete And Permissions) Then DecodePerms = DecodePerms & "Delete" & ","
    17.     If (adRightReadPermissions And Permissions) Then DecodePerms = DecodePerms & "Read Permissions" & ","
    18.     If (adRightWritePermissions And Permissions) Then DecodePerms = DecodePerms & "Write Permissions" & ","
    19.     If (adRightWriteOwner And Permissions) Then DecodePerms = DecodePerms & "Write Owner" & ","
    20.     If (adRightMaximumAllowed And Permissions) Then DecodePerms = DecodePerms & "Maximum Allowed" & ","
    21.     If (adRightFull And Permissions) Then DecodePerms = DecodePerms & "Full" & ","
    22.     If (adRightExecute And Permissions) Then DecodePerms = DecodePerms & "Execute" & ","
    23.     If (adRightUpdate And Permissions) Then DecodePerms = DecodePerms & "Update" & ","
    24.  
    25.    
    26.     ' to read in immediate window
    27.     Debug.Print DecodePerms
    28.    
    29. End Function
    Last edited by rjbudz; Jul 19th, 2005 at 10:48 AM. Reason: Corrected VB code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width