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 authenticati
In C#.Net use
Console.WriteLine("UserName: {0}", Environment.UserName);
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