[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

User

Posted on 1998-10-12
3
Medium Priority
?
141 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 40 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

865 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