identify Windows NT/98 user


thru Vb i want to identify the user currently logged into Windows NT/98/2000 session. plz suggest how to do it.

Who is Participating?
Ryan ChongConnect With a Mentor Commented:
Try GetUserName API or use Environ("USERNAME") ?
This snippet will diplay name of currently logged on user

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

Private Sub Command1_Click ()
  Dim RetVal As Long
  Dim Puffer As String * 256
  Dim UserName As String
  RetVal = GetUserName(Puffer, Len(Puffer))

  ' Bei vbNullChar "abtrennen" und anzeigen
  If RetVal <> 0 Then
      UserName = Left$(Puffer, Instr(1, Puffer, vbNullChar) - 1)    
    MsgBox "Hallo " & UserName
  End If
End Sub
Ryan ChongCommented:
Any reason why 'B' is given, navneetha?
navneethaAuthor Commented:
No dear. the answer though i did not know seem to be very simple.

but nothing in particular. was vey useful !!!!

anyway where r u from ??
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.