Solved

Find User Name

Posted on 2000-03-31
6
230 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
6 Comments
 
LVL 27

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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 142

Expert Comment

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 95
MS Access Search and Replace Using VBA 6 72
Zip Folders Using Chilkat Routines 1 40
Bartender Integration Builder 3 19
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

773 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