Retrieving the UserName of the Logged-On Person


This tip shows you how to retrieve the username of the currently logged-on user from Windows NT/2000.

How to use:
  1. Copy-paste this procedure and function declaration into the VB Editor in ArcMap.
  2. Run the procedure.
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
  (ByVal lpbuffer As String, nSize As Long) As Long

Private Sub GettingTheUserName()
  Dim sBuffer As String
  Dim sUName As String
  Dim lSize As Long
  sBuffer = Space$(255)
  lSize = Len(sBuffer)
  Call GetUserName(sBuffer, lSize)
  If lSize > 0 Then
    sUName = Left$(sBuffer, lSize)
    sUName = vbNullString
  End If
  MsgBox sUName
End Sub