0

I am using the following code for reading CPU Load on remote PC with Win XP. I have to use the credentials on the remote PC. It is working fine. But how can I use CIM session instead of WMI?

public void Read_CPU_Load_WMI()
    {      
        WMI_path = "\\\\" + TagService.IP_to_Connect + "\\root\\cimv2";
        System.Management.ConnectionOptions options = new System.Management.ConnectionOptions();
        options.Username = username;
        options.Password = password;
        ManagementScope scope = new ManagementScope(WMI_path, options);
        scope.Connect();

        SelectQuery query = new SelectQuery("select PercentProcessorTime from Win32_PerfFormattedData_PerfOS_Processor where Name='_Total'");
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);           

        foreach (ManagementObject queryObj in searcher.Get())
        {
            CPU_Load_WMI_int = Convert.ToInt16(queryObj["PercentProcessorTime"]);
            CPU_Load_WMI_str = queryObj["PercentProcessorTime"].ToString();
        }

    }

I have started as following but cannot finish it

  public void Read_CPU_Load_CIM
     {
        WMI_path = "\\\\" + TagService.IP_to_Connect + "\\root\\cimv2";            
        System.Management.ConnectionOptions options = new System.Management.ConnectionOptions();
        options.Username = username;
        options.Password = password;
        string Namespace = @"root\cimv2";
        string OSQuery = "SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor where Name='_Total'";
        CimSession mySession = CimSession.Create(WMI_path);
        IEnumerable<CimInstance> queryInstance = mySession.QueryInstances(Namespace, "WQL", OSQuery);

        //CPU_Load_WMI_int = ???
    }
Mdarende
  • 469
  • 3
  • 13

0 Answers0