Solved

User

Posted on 1998-10-12
3
134 Views
Last Modified: 2010-04-30
How do I get the Current NT LoginName?
0
Comment
Question by:TheAnswerMan
3 Comments
 
LVL 3

Accepted Solution

by:
vmano earned 10 total points
ID: 1439425
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

0
 
LVL 3

Author Comment

by:TheAnswerMan
ID: 1439426
thanks
0
 
LVL 1

Expert Comment

by:tommy_boy
ID: 1439427
what about Environ("User")?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now