Solved

Get user name in VB6

Posted on 2002-05-24
5
826 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
Comment Utility
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
Comment Utility
It´s all I need.
Thanks.
0
 
LVL 4

Expert Comment

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

Expert Comment

by:robbert
Comment Utility
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
Comment Utility
Thanks for the points, glad I could help...
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

743 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

16 Experts available now in Live!

Get 1:1 Help Now