Tools Links Login

Getting the User Name

By calling this function you can retrieve the current user name on that computer. Enjoy!

Original Author: Mike-Ejeet 9t9

Code

Place the following code into a module:
Private Declare Function GetUserName Lib "advapi32.dll" _
      Alias "GetUserNameA" (ByVal lpBuffer As String, _
      nSize As Long) As Long
Public Function UserName() As String
  Dim llReturn As Long
  Dim lsUserName As String
  Dim lsBuffer As String
  
  lsUserName = ""
  lsBuffer = Space$(255)
  llReturn = GetUserName(lsBuffer, 255)
  
  
  If llReturn Then
    lsUserName = Left$(lsBuffer, InStr(lsBuffer, Chr(0)) - 1)
  End If
  
  UserName = lsUserName
End Function

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 80 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.