Solved

Network User Name

Posted on 2004-10-01
4
737 Views
Last Modified: 2012-05-05
This is a two part question:-)

Part 1: First I am using this code to find out what computeris logged into the database:
********************************************
Function ShowUserRosterMultipleUsers() As String
    Dim cn As New ADODB.Connection
    Dim cn2 As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim i, j As Long

    cn.Provider = "Microsoft.Jet.OLEDB.4.0"
    cn.Open "Data Source=X:\CrdtAdmin\BIFiles\DTS-Deal Tracking.mde"

    cn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
    & "Data Source=X:\CrdtAdmin\BIFiles\DTS-Deal Tracking.mde"

    ' The user roster is exposed as a provider-specific schema rowset
    ' in the Jet 4 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.

   ShowUserRosterMultipleUsers = rs.Fields(0).Name & "," & rs.Fields(1).Name & "," & rs.Fields(2).Name & "," & rs.Fields(3).Name & vbCrLf

    While Not rs.EOF
        ShowUserRosterMultipleUsers = ShowUserRosterMultipleUsers & rs.Fields(0) & "," & rs.Fields(1) & "," & rs.Fields(2) & "," & rs.Fields(3) & vbCrLf
        rs.MoveNext
    Wend
    'Need to type in ShowUserRosterMultipleUsers to show list of users
   rs.Close
   Set rs = Nothing
End Function

*******************************************************************

Right now this is just dumped into a one text box.  How do I clean it up and divide it up into separate colums.

Part 2:  How do I go about pulling the network ID? in the same manner as above?

0
Comment
Question by:garland29
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 66

Assisted Solution

by:Jim Horn
Jim Horn earned 250 total points
ID: 12201459
Use this funciton/API call for Part 2.  Can't help you with Part 1.

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

Public Function fn_get_user_name() As String

'Returns the network ID of the person that logged into the machine that is running this Access application:
'This is not the same as the Access security user.

'Visual Basic Source Code Library, The Waite group, Chapter 12.5

On Error GoTo err_fn_get_user_name

Dim str_user_name As String, lng_buffer_size As Long, lng_ret_code As Long, lng_null_character_position As Long

str_user_name = Space(80)
lng_buffer_size = Len(str_user_name)

lng_ret_code = GetUserName(str_user_name, lng_buffer_size)

lng_null_character_position = InStr(str_user_name, Chr(0))
If lng_null_character_position > 0 Then
    str_user_name = left(str_user_name, lng_null_character_position - 1)
Else
    str_user_name = " "
End If

fn_get_user_name = UCase(str_user_name)

exit_fn_get_user_name:
    Exit Function
   
err_fn_get_user_name:
    fn_get_user_name = "Not able to get user name."
    Resume exit_fn_get_user_name
   
End Function
0
 

Author Comment

by:garland29
ID: 12201494
Jim,  Does this have to be in the database file that is running?  It's a MDE file and I want to be the only one that can see this.   How do I point it to the database that I want to get the username?
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 12201545
You will need to dump the above VBA code into a code module.   I haven't tried this code to detect users from a specific database, only the one the code is in, so you'll have to fiture that part out.

Also, if you are dealing with an .mde, then you'll have to find the .mdb it was created from, put the code in there, then compile it as an .mde, and redeploy.
0
 
LVL 5

Accepted Solution

by:
kemp_a earned 250 total points
ID: 12201614
This a a HUGE question!

The reason your userlist is a string of data is because of the line:
ShowUserRosterMultipleUsers = ShowUserRosterMultipleUsers & rs.Fields(0) & "," & rs.Fields(1) & "," & rs.Fields(2) & "," & rs.Fields(3) & vbCrLf

Your Function only returns a string delimeted by carriage returns!

You can re-parse the returned string in your front end code if you like, or return a collection/array, but without modifying the current code re-parse the string is better!

Part 2:
What do you mean by "network id", is it the MAC or IP address of the connection? If so, you will have to determine the FieldName/number of the connection in the rs dataset!

So your output string looks like:
ShowUserRosterMultipleUsers = ShowUserRosterMultipleUsers & rs.Fields(0) & "," & rs.Fields(1) & "," & rs.Fields(2) & "," & rs.Fields(3) & "," & rs.fields("Connection") & vbCrLf

NOTE: the "," & rs.fields("Connection") additional field to output for the string to determin the Connection

If the Connection is not available in this recordset, then you will have to try and determine it some other way

Good luck!



0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

623 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