ninjaimp 8 Junior Poster

Hi

I am trying to list all users logged into a speceific server but am getting nowhere.

Im using the below code which i have formulated from various resources but it always returns 'not logged in'. when drilling into the oReturn object it says on alot of the items that the property could not be evaluated.

Try
            Dim Strcomputer As String = "IO"

            With WMIConnectionOptions
                .Impersonation = System.Management.ImpersonationLevel.Impersonate
                .Authentication = System.Management.AuthenticationLevel.Packet
            End With

            WMIScope = New Management.ManagementScope("\\" & _
            Strcomputer & "\root\cimv2", WMIConnectionOptions)

            oq = New System.Management.ObjectQuery("SELECT UserName from Win32_ComputerSystem")
            query = New ManagementObjectSearcher(WMIScope, oq)
            queryCollection = query.Get()

            For Each oReturn As ManagementObject In queryCollection

                If Not oReturn("UserName") Is Nothing Then
                    MsgBox(oReturn("UserName").ToString)
                Else
                    MsgBox("Not logged in")
                End If

            Next



        Catch err As ManagementException

            MessageBox.Show(err.Message)

        End Try
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.