Results 1 to 2 of 2

Thread: get windows login name

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Pittsburgh, PA
    Posts
    329
    how do i find out what name a person is logged into windows as and store it in a variable?
    ______________

  2. #2
    Guest
    Use the GetUserName api function.

    Code:
    Private Declare Function GetUserName Lib "advapi32.dll" _
                Alias "GetUserNameA" (ByVal lpBuffer As String, _
                nSize As Long) As Long
    
    Public Function UserName() As String
        Dim llReturn As Long
        Dim lsUserName As String
        Dim lsBuffer As String
        
        lsUserName = ""
        lsBuffer = Space$(255)
        llReturn = GetUserName(lsBuffer, 255)
       
        If llReturn Then
           lsUserName = Left$(lsBuffer, InStr(lsBuffer, Chr(0)) - 1)
        End If
        
        UserName = lsUserName
    End Function
    
    Usage:
    
    x = UserName()
    Msgbox x

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