Solved

Get user name in VB6

Posted on 2002-05-24
5
839 Views
Last Modified: 2012-05-04
I have some PC´s in a Windows NT Network.
I need to get the user name logged in Win9x/WinME/W2000
to use in my application (VB6).
I'm using the command environ("USERNAME"),
but this command
only work in Windows 2000.
How can I get the user logon in Win9x e WinMe???
0
Comment
Question by:guiassa
[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
5 Comments
 
LVL 3

Accepted Solution

by:
SirNick earned 200 total points
ID: 7032132
Hi guiassa

Someone once gave me the following which worked for me.

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

Private Sub Form_Load()
Dim sBuffer As String
Dim lSize As Long

    sBuffer = Space$(255)
    lSize = Len(sBuffer)
    Call GetUserName(sBuffer, lSize)
    If lSize > 0 Then
        msgbox Left$(sBuffer, lSize)
    Else
        msgbox "Not found"
    End If
End Sub

Hope this helps...
0
 

Author Comment

by:guiassa
ID: 7032213
It´s all I need.
Thanks.
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 7032286
Well, then give him the points and close the question...
0
 
LVL 15

Expert Comment

by:robbert
ID: 7033604
This API function works perfectly with all required operation systems.

- This should be an "A" grade. A "B" is a grade you can give when something proposed doesn't work perfectly, and you named it, and the expert offering the solution to you was not totally able to clear your problems.
Giving the right grade is easy...

0
 
LVL 3

Expert Comment

by:SirNick
ID: 7034312
Thanks for the points, glad I could help...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

617 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