Authenticate user using Active Directory/Windows authentication in MS Access 2007

寵の児 提交于 2019-12-04 05:27:05

问题


We have application built on MSAccess 2007. We want to add a new user login concept for this application. I want to Authenticate user using Active Directory/Windows authentication.I want create a log file for this user. (like we do for .net applications using forms authentication) How do I do that on MS Access 2007.

Furthermore this application runs 24 hours, it will not be shutdown. There can be multiple users using this application. As I said this application is used 24/7, There are multiple shifts running and different users login and logout. During the user login and logout session, we need to keep track of the log for a particular user. This application uses SQL server 2005 as database server.
Your advise is a great help for me, to develop this kind of module on MS Access 2007


回答1:


Since the user has to log on to the pc, then you can simply grab their logon by using the code from http://www.mvps.org/access/api/api0008.htm:

' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If ( lngX > 0 ) Then
        fOSUserName = Left$(strUserName, lngLen - 1)
    Else
        fOSUserName = vbNullString
    End If
End Function

And, the following is a vbs script, but it should work in Access just fine also:

Displays Group Membership and Active Directory Location

The following code can be run to display the group membership of an Active Directory group and also let you know each member’s LDAP Distinguished Name. The output will name the text file the group name and will include all the members and their location in Active Directory. Just copy this into a txt file and rename to .vbs Enjoy!

Set objGroup = GetObject(“LDAP://cn=GroupName,ou=OUName,DC=DomainName,DC=local“)
Set objFileSystem = CreateObject(“Scripting.FileSystemObject”)
Set objFile = objFileSystem.OpenTextFile(objGroup.Get(“name”) & ” – Members.txt“, 2, True, 0)
For Each objMember in objGroup.Members
  objFile.WriteLine objMember.Get(“sAMAccountName”) & VbTab & _
    objMember.Get(“cn”) & VbTab & _
    objMember.Parent
Next
Set objFile = Nothing
Set objFileSystem = Nothing
Set objGroup = Nothing



回答2:


In C#.Net use

Console.WriteLine("UserName: {0}", Environment.UserName);


来源:https://stackoverflow.com/questions/5833059/authenticate-user-using-active-directory-windows-authentication-in-ms-access-200

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!