Results 1 to 5 of 5

Thread: Current User???

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Posts
    3

    Question Current User???

    I would like to know the code to show the current user logged in on a Win2000 and NT4 machine.

    thanx,

    gageseven
    Last edited by gageseven; Sep 3rd, 2001 at 06:16 PM.

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    Like this:
    VB Code:
    1. Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    2.  
    3. Private Sub Form_Load()
    4.     Dim strUserName As String
    5.     'Create a buffer
    6.     strUserName = String(100, Chr$(0))
    7.     'Get the username
    8.     GetUserName strUserName, 100
    9.     'strip the rest of the buffer
    10.     strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
    11.     'Show the username
    12.     MsgBox "Hello " + strUserName
    13. End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Posts
    3
    Thanks a bunch - works perfect

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    In addition to the user name, you can take the exact same code that chrisjk sent, replace GetUserName with GetComputerName

    Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

    and get the machine name as well.

  5. #5
    Fanatic Member
    Join Date
    Jul 2001
    Location
    London UK
    Posts
    671
    Or you could just use...

    VB Code:
    1. MsgBox Environ("UserDomain") & " " & Environ("UserName") & " " & Environ("ComputerName")

    For further info on Environ functions see DreamWeaver's post at http://forums.vb-world.net/showthrea...157#post467157

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width