Solved

Network User Name

Posted on 2004-10-01
4
717 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
  • 2
4 Comments
 
LVL 65

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 65

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

828 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