Solved

Get user name in VB6

Posted on 2002-05-24
5
829 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

914 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now