Solved

Find User Name

Posted on 2000-03-31
6
234 Views
Last Modified: 2013-11-13
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).
0
Comment
Question by:atreya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 28

Expert Comment

by:Ark
ID: 2675522
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
0
 
LVL 3

Expert Comment

by:wpsjr1
ID: 2675539
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
0
 

Expert Comment

by:AshokKumar
ID: 2675609
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.
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2675688
here, much easier :
ENVIRON("USERNAME")
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2675691
Same for computer name:
ENVIRON("COMPUTERNAME")
0
 

Accepted Solution

by:
romualdt earned 10 total points
ID: 2675767
Try this out


'Declerations
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long


       

Private Sub Command1_Click()
x = GetUser
Debug.Print x

End Sub

Function GetUser()
    ' This function uses a windows dll to qu
    '     ery the registry automatically ti return
    '     the user name
    Dim sBuffer As String
    Dim lSize As Long
    ' Parameters for the dll declaration are
    '     set
    sBuffer = Space$(255)
    lSize = Len(sBuffer)
    Call GetUserName(sBuffer, lSize) ' Call the declared dll Function


    If lSize > 0 Then
        GetUser = Left$(sBuffer, lSize) ' Remove empty spaces
    Else
        GetUser = vbNullString ' Return empty If no user is found
    End If
End Function
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article will show, step by step, how to integrate R code into a R Sweave document
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question