Results 1 to 2 of 2

Thread: Get current logged on user from 98/NT/2000 workstation?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    225

    Get current logged on user from 98/NT/2000 workstation?

    How can I find out the username of the person who is running an app. For instance, I have a program that a user uses to send information to a server app. but I would like to know the username that is submitting the data so I can add it to the data string being sent? Any ideas?

    Thanks!

  2. #2
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    here is what I have done

    VB Code:
    1. Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    2.  
    3. ' in a form
    4. Dim StrReturn As String
    5. Dim lBuffer As Long
    6. Dim LReturn As Long
    7. Dim Length As Integer
    8.  
    9. On Error GoTo checkerror
    10.  
    11. If deploytype = "3" Then
    12.     frmDesktop.Label6.Caption = User
    13.     Exit Sub
    14. End If
    15.  
    16. lBuffer = 199
    17. StrReturn = String$(200, 0)
    18. LReturn = GetUserName(StrReturn, lBuffer)
    19.  
    20. If LReturn <> 0 Then CurUser = Left$(StrReturn, lBuffer) Else CurUser = ""
    21.  
    22. Length = Len(CurUser)
    23. Length = Length - 1
    24. User = Left$(CurUser, Length)
    25.  
    26. frmDesktop.Label6.Caption = User
    27.  
    28. Exit Sub

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