Solved

Can MS Access query Active Directory?

Posted on 2007-03-19
11
8,660 Views
Last Modified: 2013-11-27
Hi All,

I am developing an Access 2003 application. The application runs from XP clients in a Windows 2003 domain environment. The app is broken into Front-end mde (XP clients) and the Back-end mdb (server).

The app is driven from a main menu bar. On this menu bar is a Maintenance Menu option. I want to control which users can use the Maintenance Menu by determining if the Active Directory logon account, which they logged onto the XP client with, is a member of a certain Active Directory group.

Can I do this in access?.

Thanks in Advance
Mick
0
Comment
Question by:ReefIT
  • 4
  • 4
  • 2
11 Comments
 
LVL 4

Accepted Solution

by:
psychakias2 earned 250 total points
ID: 18753311
Function IsMember(strDomain As String, strGroup _
   As String, strMember As String) As Boolean
  Dim grp As Object
  Dim strPath As String
 
  strPath = "WinNT://" & strDomain & "/"
  Set grp = GetObject(strPath & strGroup & ",group")
  IsMember = grp.IsMember(strPath & strMember)
End Function


And use it like this:
IsMember("YourDomain", "Administrators", "Name")
0
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 250 total points
ID: 18753313
Try adding this...

Dim si
Set si=CreateObject("ADSystemInfo")
strAdsPath=si.UserName
objUser=GetObject("LDAP://" & strAdsPath)
strUser=objUser.CN
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18753326
Missed a piece..

Dim si
Set si=CreateObject("ADSystemInfo")
strAdsPath=si.UserName
objUser=GetObject("LDAP://" & strAdsPath)
strUser=objUser.CN
strMember=Filter(objUser.MemberOf, "YourGroup")
If ubound(strMember) >= 0 Then
' User is a member of YourGroup
0
 
LVL 1

Author Comment

by:ReefIT
ID: 18754008
How do I determine the user name of the currenty logged on user account?.

Thanks
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18754015
This line, strUser=objUser.CN, should report the user name...
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:ReefIT
ID: 18754469
I get 'wrong number of arguments or invalid property assignment' error on this line:

strMember=Filter(objUser.MemberOf, "YourGroup")
0
 
LVL 4

Expert Comment

by:psychakias2
ID: 18756106
Simply use the function I mentioned in my first post like this:

IsMember("YourDomain", "Administrators", Environ$("Username"))

Just replace "YourDomain" by the domain name that you have, and "Administrators" by the group that you want to look in.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18756283
Is it likely that the user is not a member of a group, or a member of only one?

You can test for it using

If isArray(objUser.MemberOf) Then
   strMember=Filter(objUser.MemberOf, "YourGroup")
Else
   'Not a member or member of only one group
0
 
LVL 1

Author Comment

by:ReefIT
ID: 18834641
The following worked for me.

'Not all users of DIS can access the tool menu.
'This function finds out what Active Directory user account the user has logged onto the
'client PC with. It then checks to see if the account is a member of an AD group named through the
'constToolsMenuGroupName. If the account is a member, the menu is available.
    Dim objToolsMenuGroup As Object
    Dim strPath As String
    Dim blnIsMember As Boolean
    Dim objADSystemInfo As Object
    Dim arDomainDNSName() As String
       
    'Get a reference to the ADSystemInfo ActiveX object.
    Set objADSystemInfo = CreateObject("ADSystemInfo")
   
    ' Get the NetBios name of the Domain. DomainDNSName returns eg. 'reefit.local'.
    ' The split function returns 'reefit' and 'local'.
    arDomainDNSName = Split(objADSystemInfo.DomainDNSName, ".")
   
    ' arDomainDNSName(0) the netbios name. eg. 'reefit'.
    strPath = "WinNT://" & arDomainDNSName(0) & "/"
    'Get a reference to the Tools menu group.
    Set objToolsMenuGroup = GetObject(strPath & constToolsMenuGroupName & ",group")
    'Determine the AD username, and then see if it is a member of the group.
    blnIsMember = objToolsMenuGroup.IsMember(strPath & Environ$("Username"))
   
    If blnIsMember Then
        'Allow the menu to expand as normal.
    Else
        ' User account doesn't have permission to use the menu.
        ' Displaying a msgbox also stops the menu from expanding.
        MsgBox "You don't have persmission to use the Tools Menu!.", vbInformation + vbOKOnly, "Tools Menu Unavailable"
    End If
0
 
LVL 1

Author Comment

by:ReefIT
ID: 18834650
Sorry... I meant to split that between the both of you.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now