Username

How can i get the Username of both NT and Win95/98 using VB in Access 2000 ?
thomas_vAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimCotteeHead of Software ServicesCommented:
Paste the following code in a vb form with one command button. Click the button to return the logged in user / or a message if there is none. This will work on 9x/NT but not previously.

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

Private Function GetLoggedInUser(sUserName As String) As Boolean
Dim sBuff   As String * 25
Dim lRet    As Long

GetLoggedInUser = True

'Get the user name, remove NULLs, and trim trailing spaces.
lRet = GetUserName(sBuff, 25)
sUserName = Trim$(Left(sBuff, InStr(sBuff, Chr(CHAR_ZERO)) - 1))

'Return false if no name is returned.
If sUserName =  vbNullString Then
   GetLoggedInUser = False
End If

End Function

Private Sub Command1_Click()
    Dim strUserName As String
    strUserName = ""
    IF GetLoggedInUser (strUserName) Then
      MsgBox (strUserName)
    Else
      Msgbox ("No User Logged In")
    End IF
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
thomas_vAuthor Commented:
Works perfectly !!!
Thanks a lot.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Hardware

From novice to tech pro — start learning today.