ninjaimp 8 Junior Poster

Hi

I have a script that queries wmi to get logged on users.

The script works fine if i run it on the server i am query but if i choose a remote server it returns nothing. It gets the user 'logonid' but does not return anything when running the relatedquery.

Dim options As New System.Management.ConnectionOptions
        With options
            .Impersonation = System.Management.ImpersonationLevel.Impersonate
            .Authentication = System.Management.AuthenticationLevel.Default
        End With

        Dim server As String = Me.cmdServers.SelectedItem.ToString

        Dim scope As ManagementScope = New ManagementScope("\\" & server & "\root\cimv2", options)
        scope.Connect()

        Dim query As ObjectQuery
        query = New ObjectQuery("Select * from Win32_LogonSession Where LogonType = 10")
        Dim searcher As ManagementObjectSearcher
        searcher = New ManagementObjectSearcher(scope, query)
        Dim queryCollection1 As ManagementObjectCollection = searcher.Get()
        ' Get the resulting collection and loop through it
        Dim mo As ManagementBaseObject
        Dim related As RelatedObjectQuery
        For Each mo In queryCollection1
            '  MsgBox(System.Management.ManagementDateTimeConverter.ToDateTime(mo("StartTime")))
            MsgBox(mo("LogonID"))
            related = New RelatedObjectQuery("Associators of " & "{Win32_LogonSession.LogonId=" & mo("LogonId") & "} " & "Where AssocClass=Win32_LoggedOnUser ")
            Dim searcher2 = New ManagementObjectSearcher(scope, related)
            For Each objItem As ManagementObject In searcher2.Get()
                'MsgBox(objItem("Name"))
                WriteToTable(objItem("FullName"), objItem("Name"), Profilepath(GetSID(objItem("Name"))), strSID, GetProfile(objItem("Name"), "View", ""))
            Next
        Next
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.