atreya
asked on
Find User Name
By using Winsock control u can findout the Computer Name.My Question is that How to Find out the User Name (of Windows that is Login Name).
If you dont have access to the scripting hosts its:
Option Explicit
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Sub Form_Load()
Dim s$, x&
s = String$(255, 0)
x = GetUserName(s, Len(s))
Debug.Print Left$(s, x)
End Sub
Good Luck! :)
Paul
Option Explicit
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Sub Form_Load()
Dim s$, x&
s = String$(255, 0)
x = GetUserName(s, Len(s))
Debug.Print Left$(s, x)
End Sub
Good Luck! :)
Paul
wpsjr1. You came close but u might choose to print debub.print s. that's all. y all those left functions. Otherwise, atreya, u got the answer.
here, much easier :
ENVIRON("USERNAME")
ENVIRON("USERNAME")
Same for computer name:
ENVIRON("COMPUTERNAME")
ENVIRON("COMPUTERNAME")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Add reference to Windows Scripting Host
'(VB menu, project, reference)
Private Sub Command1_Click()
Dim wsh As New IWshNetwork_Class
Text1 = wsh.UserName
End Sub