[Webinar] Streamline your web hosting managementRegister Today



Posted on 1999-12-02
Medium Priority
Last Modified: 2010-04-27
How can i get the Username of both NT and Win95/98 using VB in Access 2000 ?
Question by:thomas_v
LVL 43

Accepted Solution

TimCottee earned 200 total points
ID: 2249683
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)
      Msgbox ("No User Logged In")
    End IF
End Sub

Author Comment

ID: 2249966
Works perfectly !!!
Thanks a lot.

Featured Post

Will You Be GDPR Compliant by 5/28/2018?

GDPR? That's a regulation for the European Union. But, if you collect data from customers or employees within the EU, then you need to know about GDPR and make sure your organization is compliant by May 2018. Check out our preparation checklist to make sure you're on track today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This paper addresses the security of Sennheiser DECT Contact Center and Office (CC&O) headsets. It describes the DECT security chain comprised of “Pairing”, “Per Call Authentication” and “Encryption”, which are all part of the standard DECT protocol.
If you're a modern-day technology professional, you may be wondering if certifications are really necessary. They are. Here's why.
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Suggested Courses

608 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question