Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get UserName

Status
Not open for further replies.

gbargsley

MIS
Nov 2, 2004
44
US
Hello all.

How can I grab the Login Computer UserName from a Windows 2000 Computer? I need to get this and place it into a variable, so that I can write this to the registry.

Any code that will show me to do this would be great.

Thanks in advance.
Garry B
 
Copy This Bit Into A New Module
Code:
    ' 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

Then copy This Bit Where Ever You Want It:
Code:
    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)
 
It has been documented in a FAQ.

faq222-429

Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top