Solved

Network User Name

Posted on 2004-10-01
4
704 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now