Solved

Get user name in VB6

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to set the sa password in a vb6 code for sql connection 9 55
Visual Studio 2005 text editor 10 40
MS Access 03, TransferText, decimal places 8 74
Excel Automation VBA 19 76
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

825 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