Link to home
Start Free TrialLog in
Avatar of atreya
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).
Avatar of Ark
Ark
Flag of Russian Federation image

Hi
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
Avatar of wpsjr1
wpsjr1

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
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")
Same for computer name:
ENVIRON("COMPUTERNAME")
ASKER CERTIFIED SOLUTION
Avatar of romualdt
romualdt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial