How to get current logon domain username and domain name in access 97?

J

Juno

Hi,
I have a access logon form which will first get current logon domain
username and domain name to verify the username against active directory.
Any points? Thanks in advanced.
 
J

Juno

Thanks Duane Hookom. I used that code. But I have another problem. My code
is below.

When I run the code, an error "Activex component can't create object". I
have referenced activeds.tlb.
Do I miss anything?

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

Public Function Test()
Dim MyUser As IADsUser
Dim MyCommonName As String
Dim u As String
u = fOSUserName()
' Bind to a specific user object.
Set MyUser = GetObject("LDAP://CN=" & u, "user")

' Get property
MyCommonName = MyUser.Name
MsgBox (MyCommonName)
End Function






----- Original Message -----
From: "Duane Hookom" <duanehookom@NO_SPAMhotmail.com>
Newsgroups: microsoft.public.access.modulesdaovba
Sent: Wednesday, October 27, 2004 10:34 PM
Subject: Re: How to get current logon domain username and domain name in
access 97?

 
D

Duane Hookom

The function from the site works well. I don't know what you are attempting
to do with the remainder of your code or the activeds.tlb.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top