Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Colorado, USA
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Get the User Logged on to a Workstation (Access 2K)

    (Edited by HansV to activate URL - see <!help=19>Help 19<!/help>)

    I've got an Access app that I'm working on in NT 4 in which I need to show a requestor a list of users that are connected to the data file on the server. I found MS KB article 198755 which shose the list, but it shows the workstation name and not the NT username of the user logged on to the WS. Is there a way to get this bit of info through the Windows API?

    Thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Get the User Logged on to a Workstation (Access 2K)

    Put the following code in a standard module:

    Private Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" _
    (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long

    Public Function NetUser() As String
    Dim strName As String, strUserName As String
    strName = vbNullString
    strUserName = Space(255)
    If WNetGetUser(strName, strUserName, Len(strUserName)) = 0 Then
    NetUser = Left(strUserName, InStr(strUserName, vbNullChar) - 1)
    Else
    NetUser = "-unknown-"
    End If
    End Function

    You can use the function NetUser in VBA code and in expressions in queries and controls on forms and reports.

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Get the User Logged on to a Workstation (Access 2K)

    But doesn't that just give you the name of the user logged on to the local machine? The roster will give you a list of all connections to a database, including those from other workstations, but it does it by computer name. I haven't found a way to translate those into network user names either.
    Charlotte

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Get the User Logged on to a Workstation (Access 2K)

    You're correct <img src=/S/sad.gif border=0 alt=sad width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •