A simple and light wmi framework. It has only one function: sending WMI queries. It's a subset of the System.Management.Instrumentation namespace.
The .Net framework implementation has one big problem. It leaks a little bit memory on each remote operation. Use this framework if your application is a service or runs a long time and you're sending a lot of remote queries.
This project is being distributed as a NuGet package, so open your Package Manager Console window and execute the following command:
Query all running processes for the local machine:
using(WmiConnectioncon=newWmiConnection()){foreach(WmiObjectprocessincon.CreateQuery("SELECT * FROM Win32_Process")){Console.WriteLine(process["Name"]);}}Query all partitions for a remote machine:
varopt=newWmiConnectionOptions(){EnablePackageEncryption=true};varcred=newNetworkCredential("USERNAME","PASSWORD","DOMAIN");using(WmiConnectioncon=newWmiConnection(@"\\MACHINENAME\root\cimv2",cred,opt)){foreach(WmiObjectpartitionincon.CreateQuery("SELECT * FROM Win32_DiskPartition")){Console.WriteLine(partition["Name"]);}}