C
Christopher Attard
Hi,
I'm trying to run this function which attempts to get 2 WMI properties from the specific WMI class for a process with a specified IDProcess. It's giving an "Invalid Object Path" exception. The function works when I search by process name (in this case WMI path should be: "Win32_PerfFormattedData_PerfProc_Process.Name='" +sProcessName +"'" ) but I need to search by IDProcess
public static void GetCpuUsage(string sIDProcess)
try
{
double d1,d2,n1,n2;
ManagementObject counter = new ManagementObject("Win32_PerfFormattedData_PerfProc_Process.IDProcess=" +sIDProcess);
n1 = Convert.ToDouble(counter["PercentProcessorTime"]);
d1 = Convert.ToDouble(counter["TimeStamp_Sys100NS"]);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
Any suggestions about what might be wrong in this code? Thanks in advance.
Chris
I'm trying to run this function which attempts to get 2 WMI properties from the specific WMI class for a process with a specified IDProcess. It's giving an "Invalid Object Path" exception. The function works when I search by process name (in this case WMI path should be: "Win32_PerfFormattedData_PerfProc_Process.Name='" +sProcessName +"'" ) but I need to search by IDProcess
public static void GetCpuUsage(string sIDProcess)
try
{
double d1,d2,n1,n2;
ManagementObject counter = new ManagementObject("Win32_PerfFormattedData_PerfProc_Process.IDProcess=" +sIDProcess);
n1 = Convert.ToDouble(counter["PercentProcessorTime"]);
d1 = Convert.ToDouble(counter["TimeStamp_Sys100NS"]);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
Any suggestions about what might be wrong in this code? Thanks in advance.
Chris