Returning windows username with vba

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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

Thanks,
Mike
 
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
 
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
 
Back
Top