Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[COLOR=blue] Dim searcher As New ManagementObjectSearcher("\\yourservername\root\cimv2", "SELECT * FROM Win32_ComputerSystem")
Dim queryCollection As ManagementObjectCollection = searcher.Get()
For Each queryObj As ManagementObject In queryCollection
MsgBox($"Logged in user: {queryObj("UserName")}")
Next[/color]
Dim searcher As New ManagementObjectSearcher("\\yourservername\root\cimv2", "SELECT * FROM Win32_ComputerSystem")
Dim queryCollection As ManagementObjectCollection = searcher.Get()
Dim searcher As New ManagementObjectSearcher("\\XXXXXXXXXXXXX\root", "SELECT * FROM Win32_ComputerSystem") ' \\An2PreODSApp001\root\cimv2
Dim queryCollection As ManagementObjectCollection = searcher.Get()
Dim lsLogStr As String = ""
For Each queryObj As ManagementObject In queryCollection
' MsgBox($"Logged in user: {queryObj("UserName")}")
lsLogStr += queryObj.ToString() + vbCrLf
Next
[COLOR=blue]Dim searcher As New ManagementObjectSearcher("\\YOURSERVERNAME\root[b][COLOR=red]\cimv2[/color][/b]", "SELECT * FROM Win32_ComputerSystem") '
Dim queryCollection As ManagementObjectCollection = searcher.Get()
Dim lsLogStr As String = ""
For Each queryObj As ManagementObject In queryCollection
lsLogStr += [b][COLOR=red]queryObj("UserName").ToString() + vbCrLf[/color][/b]
Next[/color]
Dim searcher As New ManagementObjectSearcher("\\XXXXXXXXX\root\[COLOR=#CC0000][b]cimv2[/b][/color]", _
"SELECT * FROM Win32_ComputerSystem")
Dim queryCollection As ManagementObjectCollection = searcher.Get()
Dim lsLogStr As String = ""
For Each queryObj As ManagementObject In queryCollection
lsLogStr += queryObj.ToString() + vbCrLf
Next
'====================================================================================================================================
Public Function GetUserNames(ByVal tcMachineName) As String
'====================================================================================================================================
' Purpose : Returns the list of the User Names currently logged into the givem machine.
' Description : Engages ManagementObject[Collection] class[es] to query system logs for the currently logged in User Names.
' Parameters : The Machine name.
' Returns : List of the User Names, separated by CRLF, currently logged into the given machine.
' Side effects : None.
' Notes : 1. Generic.
' 2. Complies with .NET Framework ver. 1.1 and higher.
' 3. On error, returns the error description, which starts with "Error occurred" phrase.
' Author : Ilya I. Rabyy
' Revisions : by Ilya on 2024-04-09 - started 1st draft.
'====================================================================================================================================
Dim lsLogStr As String = ""
' Parameter verification
If (TypeOf tcMachineName IsNot String) Then
lsLogStr = "Error occurred: the Machine Name parameter is not of type String!"
Return lsLogStr
End If
Dim lcMachineName As String = Strings.Trim(tcMachineName)
If String.IsNullOrEmpty(lcMachineName) Then
lsLogStr = "Error occurred: the Machine Name parameter must not be empty!"
Return lsLogStr
End If
' Format the Machine Name
If Not Left(lcMachineName, 2) = "\\" Then
If Not Left(lcMachineName, 1) = "\" Then
lcMachineName = "\\" + lcMachineName
Else
lcMachineName = "\" + lcMachineName
End If ' Not Left(lcMachineName, 1) = "\"
End If ' Not Left(lcMachineName, 2) = "\\"
lcMachineName = AddBackSlash(lcMachineName)
' Parameter's been validated (it seems).
' Let's get digging! But keep in mind that if it's a network server, it might be unavailable, hence Try-Catch-EndTry construct.
Try
Dim loSearcher As New ManagementObjectSearcher(lcMachineName + "root\cimv2", "SELECT * FROM Win32_ComputerSystem")
Dim loQueryCollection As ManagementObjectCollection = loSearcher.Get()
For Each loQueryObj As ManagementObject In loQueryCollection
lsLogStr += loQueryObj("UserName").ToString() + vbCrLf
Next
Catch loErr As Exception
lsLogStr = Read_Exception(loErr)
End Try
Return lsLogStr
End Function
'====================================================================================================================================