Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Who's in here?"

Status
Not open for further replies.

IlyaRabyy

Programmer
Nov 9, 2010
571
US
Colleagues,
How do I know who's currently logged in on a server (or even local W/S) machine?
IOW, I need a function that returns a list of currently logged UserIDs, whether as a String (e.g. CSV, or CRLF-, or whatever char separated) or String().

I recon posting similar Q. here before (way B4, in Feb. 2024), and I've gotten an answer with this code (slightly modified, or rather "beautified"):

C#:
Dim loLog As New EventLog("Security")
Dim loEventLogEntry As EventLogEntry
Dim loLog As New EventLog("Security")
Dim liMostRecent As Long
Dim lnCurrent As Long

Dim lsRet As String = "", llGoOn As Boolean = True, lsLogStr As String = "", lsUNs As String = ""

    liMostRecent = loLog.Entries.Count - 1

    For lnCurrent = liMostRecent To 0 Step -1
        loEventLogEntry = loLog.Entries(lnCurrent)

        If loEventLogEntry.InstanceId = 4663 Then ' file access audit event
            lsRet = LookupSID(loEventLogEntry.ReplacementStrings(0)) + " on " + Environment.MachineName + " at " + _
                        loEventLogEntry.TimeGenerated.ToString + vbCrLf
            Exit For
        End If

    Next

I tried to implement it in my program - and it caused another function there to err (don't ask me why, I couldn't figure it out).

So, I have to ask again:
Is there a way, other than the one above, to programmatically produce the listing of UserIDs of the currently logged Users?

TIA!

Regards,
Ilya


P.S. If this collection of threads is dedicated to the VB .NET, why there's no option for it for the code type braces?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top