VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Getting the User Name

by Mike-Ejeet 9t9 (5 Submissions)
Category: Internet/HTML
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (38 Votes)

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

Rate Getting the User Name

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
 

Download this snippet    Add to My Saved Code

Getting the User Name Comments

No comments have been posted about Getting the User Name. Why not be the first to post a comment about Getting the User Name.

Post your comment

Subject:
Message:
0/1000 characters