by Ghaffar Nagafpour (5 Submissions)
Category: Windows API Call/Explanation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 6th August 2005
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Find Windows UserName
API Declarations
'Email:[email protected]
'Location:Iran-Mazandaran-Tonekabon
'*****************************************
'Add 1CommandButton and 1Label to form
Private Declare Function GetUserNameA Lib "advapi32.dll" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function GetUserName() As String
Dim UN As String * 255
Call GetUserNameA(UN, 255)
GetUserName = Left$(UN, InStr(UN, Chr$(0)) - 1)
End Function
Label1.Caption = GetUserName
End Sub