在MS Access 2007中使用Active Directory / Windows身份验证对用户进行身份验证

时间:2011-04-29 14:01:24

标签: winforms ms-access ms-access-2007

我们在MSAccess 2007上构建了应用程序。我们希望为此应用程序添加新的用户登录概念。 我想使用Active Directory / Windows身份验证对用户进行身份验证。我想为此用户创建一个日志文件。 (就像我们使用表单身份验证的.net应用程序一样) 我如何在MS Access 2007上执行此操作。

此外,此应用程序运行24小时,不会关闭。可以有多个用户使用此应用程序。 正如我所说,这个应用程序是24/7使用,有多个班次运行和不同的用户登录和注销。 在用户登录和注销会话期间,我们需要跟踪特定用户的日志。 此应用程序使用SQL Server 2005作为数据库服务器 您的建议对我来说是一个很好的帮助,在MS Access 2007上开发这种模块

3 个答案:

答案 0 :(得分:0)

由于用户必须登录到电脑,因此您可以使用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

并且,以下是一个vbs脚本,但它也可以在Access中正常工作:

Displays Group Membership and Active Directory Location

  

可以运行以下代码来显示a的组成员身份   Active Directory组,还可以让您了解每个成员的LDAP   专有名称。输出将文本文件命名为组名   并将包括所有成员及其在Active中的位置   目录。只需将其复制到txt文件并重命名为.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

答案 1 :(得分:0)

在C#.Net中使用

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

答案 2 :(得分:0)

在 Access 中使用 VBA 非常简单。

Dim User As String
    Let User = Application.UserName
Dim arrUser
    Let arrUser = split(User, ",")
    User = arrUser(1)
    arrUser = split(User, "@")
    User = arrUser(0)

这在我的 VBA 应用中似乎对我有用。