0 Replies - 788 Views - Last Post: 31 July 2012 - 10:33 AM Rate Topic: -----

#1 meherbst  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-July 10

Win32 Performance Data for All Users

Posted 31 July 2012 - 10:33 AM

Hello,

I have written a small console app that lists performance data. The application in itself works fine however when I use it on my terminal server I only get the processes for the user I am logged in with which in this case is the administrator. I need to be able to see this data for all users. See code below is there a way to do this using the Win32 query or do I need to start over using something else? The data must include the CPU usage and ProcID. I have tried other ideas such as the get process functions which allow me to get processes for all users but they do not allow me to get the CPU percentage directly like the Win32 Performance data does.

Imports System.Management
Imports System

Module Module1

    Sub Main()

        Using searcher As New ManagementObjectSearcher(( _
            "SELECT * FROM Win32_PerfFormattedData_PerfProc_Process"))
            Using results As ManagementObjectCollection = searcher.Get
                For Each result As ManagementObject In results
                    Dim processId As UInteger = DirectCast(result.GetPropertyValue("IDProcess"), UInteger)
                    Dim processName As String = DirectCast(result.GetPropertyValue("Name"), String)
                    Dim cpu As ULong = DirectCast(result.GetPropertyValue("PercentProcessorTime"), ULong)
                    result.Dispose()
                    If processName = "iexplore" Then
                        Console.WriteLine("{0} - {1} - {2}", processId, processName, cpu)
                    End If

                Next
            End Using
        End Using
    End Sub

End Module



Is This A Good Question/Topic? 0
  • +

Page 1 of 1