Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
| Search | Today's Posts | Mark Forums Read
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 27th, 2007, 11:04 AM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default How Can I Get the Name of the Current User?

I need to find out what the application thinks is the name of the user under which it is operating.
 
Old March 27th, 2007, 12:28 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Code:
Private Declare Function GetUserName _
                Lib     "advapi32.dll" _
                Alias   "GetUserNameA" ( ByVal lpBuffer As String, _
                                               nSize    As Long _
                                       ) As Long

    .  .  .


    Dim lngCnt  As Long
    Dim lngRtrn As Long
    Dim sUserNm As String * 150

    lngRtrn = GetUserName(sUserNm, 149)
    lngCnt  = InStr(sUserNm, Chr$(0))

    If lngCnt < 2 Then
        MsgBox "No UserName obtained."
    Else
        sUserNm = Left$(sUserNm, lngCnt - 1)
        MsgBox "UserName = """ & sUserNm & """"
    End If




Similar Threads
Thread Thread Starter Forum Replies Last Post
How Can I Get the Name of the Current User? BrianWren Pro VB 6 0 March 27th, 2007 11:42 AM
Access ADP - Getting Current User Name Scripts82 Access VBA 2 March 8th, 2006 09:38 PM
Showing Current User Detail qwer Access 1 November 2nd, 2005 05:16 PM
Current user type dotnetprogrammer VS.NET 2002/2003 0 February 1st, 2005 07:20 AM
current user schockp Oracle 2 November 12th, 2003 06:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.