WmiSharp 0.0.2

dotnet add package WmiSharp --version 0.0.2                
NuGet\Install-Package WmiSharp -Version 0.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WmiSharp" Version="0.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WmiSharp --version 0.0.2                
#r "nuget: WmiSharp, 0.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install WmiSharp as a Cake Addin
#addin nuget:?package=WmiSharp&version=0.0.2

// Install WmiSharp as a Cake Tool
#tool nuget:?package=WmiSharp&version=0.0.2                

WmiSharp

nuget

GitHub Issues

Usage

This project is still early in its development and I currently provide a few models for you to use but it is easy to create your own.

Model Classes

You can map a query to a class reference type, for example the LogicalDrive class below is currently mapped to the Win32_LogicalDisk wmi class. You can see the use of the WmiNameAttribute which allows you to map the actual WMI property name to a more relatable one with in your code.

    [WmiClass("Win32_LogicalDisk")]
    public class LogicalDrive
    {
        [WmiName("DeviceId")]
        public string DriveLetter { get; set; }

        public ulong FreeSpace { get; set; }
        public ulong Size { get; set; }

        [WmiName("VolumeName")]
        public string Name { get; set; }
    }

Within the OperatingSystem class you can see it maps to Win32_OperatingSystem but also includes returnsSingle in the attribute. When querying Win32_OperatingSystem it doesn't return a list of information similar to how Win32_LogicalDisk or many other WMI classes do. It returns a single result of information and this setting is used to ensure the right Query method is used when executing so instead of returning a List containing one object you get the object itself. Another attribute visible here is the NotMappedAttribute (From the System.ComponentModel.DataAnnotations.Schema, may create a custom one at some point) which tells the system when mapping the returned data to the object to not bother with that property and nothing needs to be mapped to it.

    [WmiClass(name: "Win32_OperatingSystem", returnsSingle: true)]
    public class OperatingSystem
    {
        public string Version { get; set; }

        [WmiName("FreePhysicalMemory")]
        public ulong PhysicalMemoryFree { get; set; }

        [WmiName("TotalVisibleMemorySize")]
        public ulong PhysicalMemoryAmount { get; set; }

        [WmiName("OSArchitecture")]
        public string Architecture { get; set; }

        [NotMapped]
        public ulong PhysicalMemoryInUse
        {
            get
            {
                return this.PhysicalMemoryAmount - this.PhysicalMemoryFree;
            }
        }
    }

Execution

As of right now there is basic remote execution which is overloaded in var wmi = new Wmi(). For simplicity here is how to run it against the current running system.

  // Initialize the new Wmi object.
  var wmi = new Wmi();
  
  // Query all the processes from `Win32_Process` that was defined in the `WmiClassAttribute` inside the model.
  await q.QueryMany<Process>();
  
  // Query the single result from `Win32_OperatingSystem` that was defined in the `WmiClassAttribute` inside the model.
  var output2 = await q.Query<Core.Models.OperatingSystem>();
  
  // Query the single result from the `Win32_OperatingSystem` using a direct query which only selects the version.
  // Only the version will show up as mapped all other properties will be their null/default values. It will try to map all properties even you tried to select only the version hopefully this can be changed in a future version.
  var output2 = await q.Query<Core.Models.OperatingSystem>("SELECT Version FROM Win32_OperatingSystem");
  
  // Query all the processes from `Win32_Process` using a where statement. This will only return you the processes with a ProcessId greater than 8.
  await q.QueryMany<Process>("SELECT * FROM Win32_Process WHERE WHERE ProcessId > 8");
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.2 is compatible.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.2 608 3/4/2019