Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving Logged-in User's userid from Active Directory 1

Status
Not open for further replies.

WynneSMI

Programmer
Dec 16, 2002
76
0
0
US
I need to know how to retrieve the user id of the currently logged-in user from Active Directory. Is there an API call or a function what will give me this information? Thanks.
 
Hi!

You can try using the CurrentUser function:

MyUser = CurrentUser

This does not always work, if it doesn't you can use the following:

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public 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 = &quot;&quot;
End If

End Function

MyUser = fosUserName()

hth


Jeff Bridgham
bridgham@purdue.edu
 
Hi!

Forgot to say that the API call came to me originally from a friend of mine. Where he might of gotten it I cannot say.

:)


Jeff Bridgham
bridgham@purdue.edu
 
Thanks, I think this is just what I need!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top