• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 142
  • Last Modified:


How do I get the Current NT LoginName?
1 Solution
Type the following code into a new module:
     ' Makes sure all variables are dimensioned in each subroutine.
     Option Explicit
     ' Access the GetUserNameA function in advapi32.dll and
     ' call the function GetUserName.
     Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
     (ByVal lpBuffer As String, nSize As Long) As Long
     ' Main routine to Dimension variables, retrieve user name
     ' and display answer.
     Sub Get_User_Name()
     ' Dimension variables
     Dim lpBuff As String * 25
     Dim ret As Long, UserName As String
     ' Get the user name minus any trailing spaces found in the name.
     ret = GetUserName(lpBuff, 25)
     UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
     ' Display the User Name
     MsgBox UserName
     End Sub

TheAnswerManAuthor Commented:
what about Environ("User")?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now