Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
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.
Reply With Quote
  #2 (permalink)  
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 08:38 PM
Showing Current User Detail qwer Access 1 November 2nd, 2005 04:16 PM
Current user type dotnetprogrammer VS.NET 2002/2003 0 February 1st, 2005 06:20 AM
current user schockp Oracle 2 November 12th, 2003 05:18 AM



All times are GMT -4. The time now is 06:36 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.