Returning windows username with vba

G

Guest

Hi,
Does anyone know how to return the username with which the current user
logged onto the windows domain?

Thanks,
Mike
 
S

Siddharth Parekh

You can either use the environ() method or the getusername() api.

HTH
Siddharth.
Hi,
Does anyone know how to return the username with which the current user
logged onto the windows domain?

Thanks,
Mike
 
A

Alex

Hi,

put the following in a module

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

Function ap_GetUserName() As Variant
On Error GoTo Err_ap_GetUserName
Dim strUserName As String
Dim lngLength As Long
Dim lngResult As Long
'-- Set up the buffer
strUserName = String$(255, 0)
lngLength = 255
'-- Make the call
lngResult = wu_GetUserName(strUserName, lngLength)
'-- Assign the value
ap_GetUserName = strUserName
Exit_ap_GetUserName:
Exit Function
Err_ap_GetUserName:
MsgBox Err.Description & vbCrLf & Erl()
Resume Next
End Function


and call the above function and it will return the nt/domain login

and problems post back here.

regards

Alex
 

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