Advertisement
Guest User

WMI INVALID CLASS

a guest
Feb 25th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Management;
  11.  
  12. namespace WMITest
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         private void button1_Click(object sender, EventArgs e)
  22.         {
  23.             MessageBox.Show(Dump());
  24.         }
  25.  
  26.         string Dump()
  27.         {
  28.             string HOST = "WILLIAM-PC";
  29.             string Data = "";
  30.  
  31.             try
  32.             {
  33.                 ConnectionOptions CO = new ConnectionOptions();
  34.                 CO.Authentication = AuthenticationLevel.Packet;                
  35.  
  36.                 ManagementScope Scope = new ManagementScope(@"\\" + HOST + @"\root\cimv2", CO);
  37.  
  38.                 Scope.Connect();
  39.  
  40.                 if (! Scope.IsConnected)
  41.                 {
  42.                     MessageBox.Show("Not connected!");
  43.                 }
  44.  
  45.                 Scope.Options.EnablePrivileges = true;
  46.  
  47.                 SelectQuery Query = new SelectQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Memory");
  48.  
  49.                 ManagementObjectSearcher MOS = new ManagementObjectSearcher(Scope, Query);
  50.  
  51.                 foreach (ManagementObject MO in MOS.Get())
  52.                 {
  53.                     foreach (PropertyData PD in MO.Properties)
  54.                     {
  55.                         Data = Data + PD.Name + " = " + PD.Value + "\n";
  56.                     }
  57.                 }
  58.  
  59.                 return Data;
  60.             }
  61.             catch (Exception E)
  62.             {
  63.                 return "Exception: " +E.Message ;  
  64.             }
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement