locked
Total Idle Processor Time

    Pregunta

  • In attempting to monitor several aspects of various systems due to software problems it was determined to collect Process information from systems experiencing the problem to compair with systems that were operating without problems.

    In addition it was determined that the Idle Processor time also be compared.

    However, The system throws an Access Denied Error whenever you try to access the StartDate or TotalProcessorTime for the "Idle" Process.

    This code works

    Dim CurrProc() As Process  
    CurrProc = Process.GetProcesses  
    Dim TaskTime as TimeSpan  
    Dim TaskStart as Date  
    For Each ActiveTask As Process In CurrProc  
        If ActiveTask.ProcessName <> "Idle" Then  
            TaskStart = ActiveTask.StartTime  
            TaskTime = ActiveTask.TotalProcessorTime  
            MessageBox.Show(TaskStart.ToLocalTime & vbNewLine & TaskTime.ToString, ActiveTask.ProcessName, MessageBoxButtons.OK)  
        End If  
    Next 

    However, I also want to get the TotalProcessorTime that the system was Idle.
    If I remove the If statement then the program throws an Access Denied Error.

    This is displayed in the task manager so I thought that it would be accessable through the Idle Process.
    I know that the Idle Process is a Virtual Process but since the system assigns time to this is there some way to retrive the information?


    Roger
    lunes, 05 de enero de 2009 22:01

Respuestas

  • Hi Roger,

    Take a look at the WMI in this scenario. search WMI code creator tool for your use.


    Imports System
    Imports System.Management
    Imports System.Windows.Forms
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                Dim searcher As New ManagementObjectSearcher( _
                    "root\CIMV2", _
                    "SELECT * FROM Win32_PerfFormattedData_PerfProc_Process")
                For Each queryObj As ManagementObject In searcher.Get()
                    If (queryObj("Name").ToString.ToLower = "idle") Then
                        Console.WriteLine(queryObj("Name"))
                        Console.WriteLine("-----------------------------------")
                        Console.WriteLine("Win32_PerfFormattedData_PerfProc_Process instance")
                        Console.WriteLine("-----------------------------------")
                        Console.WriteLine("ElapsedTime: {0}", queryObj("ElapsedTime"))
                    End If
                Next

            Catch err As ManagementException
                MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
            End Try
        End Sub
    End Class

    Riquel

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    viernes, 09 de enero de 2009 3:16
    Moderador

Todas las respuestas

  • Its not the process per-say, but the permissions that you have to the process.  If I run your posted code on my machine it fails - there are a number of other processes that also throw the Access Denied Error.

    The short answer is to make sure the user account under which the application runs has full privileges on the computer - but even that may not be enough to access every possible process.

    Any reason why you didn't use the windows performance monitor to gather this data instead of trying to write your own utility?
    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
    lunes, 05 de enero de 2009 23:27
    Moderador
  • The Program runs under the Administrator account but still only throws the error on the Idle Process.
    I have check this on several platforms (Only needs to work with XP).

    This utility collects much more data than just the Process information and outputs the data to a file.
    That file is then collected since the program is ran on remote systems many of which do not have network access.

    The code is just a Snippit to show what I was attempting.
    One of the main reasons that I wanted the Idle Processor time is I am looking to find out how long the system has ran since the last reboot.

    It is known that some of the systems have ran for several months without a reboot.
    Roger
    martes, 06 de enero de 2009 0:42
  • You might need the application to run as System - I'm not sure what the answer is (sorry), but since it is a permissions issue you'll need to do something about elevating the application's permissions.
    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
    martes, 06 de enero de 2009 3:57
    Moderador
  • Hi Roger,

    Take a look at the WMI in this scenario. search WMI code creator tool for your use.


    Imports System
    Imports System.Management
    Imports System.Windows.Forms
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                Dim searcher As New ManagementObjectSearcher( _
                    "root\CIMV2", _
                    "SELECT * FROM Win32_PerfFormattedData_PerfProc_Process")
                For Each queryObj As ManagementObject In searcher.Get()
                    If (queryObj("Name").ToString.ToLower = "idle") Then
                        Console.WriteLine(queryObj("Name"))
                        Console.WriteLine("-----------------------------------")
                        Console.WriteLine("Win32_PerfFormattedData_PerfProc_Process instance")
                        Console.WriteLine("-----------------------------------")
                        Console.WriteLine("ElapsedTime: {0}", queryObj("ElapsedTime"))
                    End If
                Next

            Catch err As ManagementException
                MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
            End Try
        End Sub
    End Class

    Riquel

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    viernes, 09 de enero de 2009 3:16
    Moderador