VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Retrieve the Windows user name

by Anonymous (267 Submissions)
Category: Windows System Services
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Wed 16th December 1998
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Retrieve the Windows user name

API Declarations


' call the function GetUserName.
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Rate Retrieve the Windows 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

Download this snippet    Add to My Saved Code

Retrieve the Windows user name Comments

No comments have been posted about Retrieve the Windows user name. Why not be the first to post a comment about Retrieve the Windows user name.

Post your comment

Subject:
Message:
0/1000 characters