Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 844
  • Last Modified:

Get user name in VB6

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
guiassa
Asked:
guiassa
1 Solution
 
SirNickCommented:
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
 
guiassaAuthor Commented:
It´s all I need.
Thanks.
0
 
trkcorpCommented:
Well, then give him the points and close the question...
0
 
robbertCommented:
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
 
SirNickCommented:
Thanks for the points, glad I could help...
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now