Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Determine Windows Userid for Current Db Users

Discussion in 'Information Technology' started by microb0x, Jul 28, 2006.

  1. microb0x

    microb0x
    Expand Collapse
    Guest

    I have a function in place to determine the current user roster for an
    access db. I will paste that sub below. The results of this function
    provide me with the Computer_Name, Login_Name(access's not windows),
    Connected, and Suspect_State.

    My question is, is there a way for me to gather all the windows logins
    for every user currently in the db? The computer name is nice, but not
    much use to me as I dont have a quick reliable way to attach a person
    to a computer name. Additionaly some of my access applications are
    accessed via a citrix environment so in those cases the computer name
    is just a citrix server, and I have no way of attaching that to a user.

    Basically I need the windows ID for all users that are in my database
    as a given time.

    Here is my current sub for determining the computer name(courtesy of
    another user in this group):


    Sub ShowUserRosterMultipleUsers()
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim i, j As Long

    'Set cn = CurrentDb.Connection
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & vDbPath

    ' The user roster is exposed as a provider-specific schema rowset
    ' in the Jet 4.0 OLE DB provider. You have to use a GUID to
    ' reference the schema, as provider-specific schemas are not
    ' listed in ADO's type library for schema rowsets

    Set rs = cn.OpenSchema(adSchemaProviderSpecific, _
    , "{947bb102-5d43-11d1-bdbf-00c04fb92675}")

    'Output the list of all users in the current database.

    DoCmd.OpenForm "frmDbUsers_Data"
    With Form_frmDBUsers_Data.lstUsers
    .AddItem (rs.Fields(0).Name & ";" & rs.Fields(1).Name & _
    ";" & rs.Fields(2).Name & ";" & rs.Fields(3).Name)
    End With

    While Not rs.EOF
    With Form_frmDBUsers_Data.lstUsers
    .AddItem (Left(Trim(rs.Fields(0)), Len(Trim(rs.Fields(0)))
    - 1) & _
    ";" & Left(Trim(rs.Fields(1)),
    Len(Trim(rs.Fields(1))) - 1) & _
    ";" & Trim(rs.Fields(2)) & ";" &
    Trim(rs.Fields(3)))
    End With
    rs.MoveNext
    Wend


    rs.Close
    cn.Close
    Set rs = Nothing
    Set cn = Nothing

    End Sub
     
  2. Loading...

    Similar Threads Forum Date
    Nature Scientists Determine Earth has 8.7 Million Species Breaking News Aug 26, 2011
    Sikh Preacher Determined to Keep Speaking Sikh Sikhi Sikhism Apr 6, 2010
    Sikh News Joe Biden runs into a determined young Sikh Girl Breaking News May 23, 2009
    Sikh News Punjab govt determined to eliminate child labour: Minister (Outlook India) Breaking News Nov 14, 2007
    Free/ Pre-determined Human Will? Interfaith Dialogues Oct 31, 2006

  3. Michael H

    Michael H
    Expand Collapse
    Guest

    Hi.

    Paste the following code (courtesy of Dev Ashish) into a new module, and use
    the fOSUserName function. You may also want to have a look here:
    http://www.mvps.org/access/api/api0066.htm


    Option Compare Database
    Option Explicit

    '******************** Code Start **************************
    ' This code was originally written by Dev Ashish.
    ' It is not to be altered or distributed,
    ' except as part of an application.
    ' You are free to use it in any application,
    ' provided the copyright notice is left unchanged.
    '
    ' Code Courtesy of
    ' Dev Ashish
    '
    Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

    Function fOSUserName() As String
    ' Returns the network login name
    Dim lngLen As Long, lngX As Long
    Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If (lngX > 0) Then
    fOSUserName = Left$(strUserName, lngLen - 1)
    Else
    fOSUserName = vbNullString
    End If
    End Function
    '******************** Code End **************************



    -Michael



    "microb0x" wrote:

    > I have a function in place to determine the current user roster for an
    > access db. I will paste that sub below. The results of this function
    > provide me with the Computer_Name, Login_Name(access's not windows),
    > Connected, and Suspect_State.
    >
    > My question is, is there a way for me to gather all the windows logins
    > for every user currently in the db? The computer name is nice, but not
    > much use to me as I dont have a quick reliable way to attach a person
    > to a computer name. Additionaly some of my access applications are
    > accessed via a citrix environment so in those cases the computer name
    > is just a citrix server, and I have no way of attaching that to a user.
    >
    > Basically I need the windows ID for all users that are in my database
    > as a given time.
    >
    > Here is my current sub for determining the computer name(courtesy of
    > another user in this group):
    >
    >
    > Sub ShowUserRosterMultipleUsers()
    > Dim cn As New ADODB.Connection
    > Dim rs As New ADODB.Recordset
    > Dim i, j As Long
    >
    > 'Set cn = CurrentDb.Connection
    > cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & vDbPath
    >
    > ' The user roster is exposed as a provider-specific schema rowset
    > ' in the Jet 4.0 OLE DB provider. You have to use a GUID to
    > ' reference the schema, as provider-specific schemas are not
    > ' listed in ADO's type library for schema rowsets
    >
    > Set rs = cn.OpenSchema(adSchemaProviderSpecific, _
    > , "{947bb102-5d43-11d1-bdbf-00c04fb92675}")
    >
    > 'Output the list of all users in the current database.
    >
    > DoCmd.OpenForm "frmDbUsers_Data"
    > With Form_frmDBUsers_Data.lstUsers
    > .AddItem (rs.Fields(0).Name & ";" & rs.Fields(1).Name & _
    > ";" & rs.Fields(2).Name & ";" & rs.Fields(3).Name)
    > End With
    >
    > While Not rs.EOF
    > With Form_frmDBUsers_Data.lstUsers
    > .AddItem (Left(Trim(rs.Fields(0)), Len(Trim(rs.Fields(0)))
    > - 1) & _
    > ";" & Left(Trim(rs.Fields(1)),
    > Len(Trim(rs.Fields(1))) - 1) & _
    > ";" & Trim(rs.Fields(2)) & ";" &
    > Trim(rs.Fields(3)))
    > End With
    > rs.MoveNext
    > Wend
    >
    >
    > rs.Close
    > cn.Close
    > Set rs = Nothing
    > Set cn = Nothing
    >
    > End Sub
    >
    >
     
  4. Smartin

    Smartin
    Expand Collapse
    Guest

    Michael H wrote:
    > Hi.
    >
    > Paste the following code (courtesy of Dev Ashish) into a new module, and use
    > the fOSUserName function. You may also want to have a look here:
    > http://www.mvps.org/access/api/api0066.htm
    >
    >


    That and the related functions from Dev Ashish are brilliant and
    probably the best ever for diagnosing issues in multiple user Access
    databases. If anyone ever bumps into him, please shake his hand for me.

    --
    Smartin
     
  5. microb0x

    microb0x
    Expand Collapse
    Guest

    Michael H and/or Smartin,

    Do the solution(s) you posted just retrieve the windows login for a
    single user or all users currently in the db?

    I think I already have a similar function for determining the windows
    login for a user who is accessing the FE.

    What I'm looking for is the ability to, using a access application I
    wrote, point at an external access file and retrieve all the users who
    are currently connected to it. I need to point to my BE file and have
    it tell me who is currently connected.

    Like I said in my initial post I can gather the computer name of each
    person connected but I'm unsure how to get the windows login for each
    person.
     

Share This Page