WMI2CSharp 2.0.2

Additional Details

Please use version 2.1.1 or newer

There is a newer version of this package available.
See the version list below for details.
dotnet add package WMI2CSharp --version 2.0.2                
NuGet\Install-Package WMI2CSharp -Version 2.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="WMI2CSharp" Version="2.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WMI2CSharp --version 2.0.2                
#r "nuget: WMI2CSharp, 2.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 WMI2CSharp as a Cake Addin
#addin nuget:?package=WMI2CSharp&version=2.0.2

// Install WMI2CSharp as a Cake Tool
#tool nuget:?package=WMI2CSharp&version=2.0.2                

WMI2CSharp

Description

WMI2CSharp is a library for Windows Management Instrumentation Object Relational Mapping. It will fetch data upon provided access information and hostname. Task optimized and parameterizable to minimize fetch time.

Sample Usage

Simple

var searchInformationCategories = new[]
{
    InformationCategory.OperatingSystem,
    InformationCategory.InternalHardware,
    InformationCategory.Network,
    InformationCategory.Software,
    InformationCategory.System,
    InformationCategory.User,
    InformationCategory.Application
};

var searchInformationTypes = new[]
{
    InformationType.OperatingSystem,
    InformationType.SerialPort
};

var hostNames = new[] { "HostName1", "HostName2", "HostName3" };
var devices = new List<Device>(await new DeviceCollection()
                                        .WithCredentials(new CredentialsProvider("UserName","Password"))
                                        .WithInformationCategories(searchInformationCategories)
                                        .WithInformationTypes(searchInformationTypes)
                                        .GetDevicesAsync(hostNames)
                                        .ConfigureAwait(false));

Advanced

The cancellation token will cancel all incomplete tasks, that means the result from GetDevicesAsync only returns finished devices that have completed all the data fetching.

var cancellationTokenSource = new CancellationTokenSource();
cancellationTokenSource.CancelAfter(new TimeSpan(0, 1, 0));
var cancellationToken = cancellationTokenSource.Token;

var dataFilesPath = @"C:\\Path\\";
var hostNames = new[] { "HostName1", "HostName2", "HostName3" };
var deviceCollection = new DeviceCollection();
var devices = await deviceCollection
                    .WithCredentials(new CredentialsProvider("UserName","Password"))
                    .Where(InformationType.DataFiles, $"{nameof(DataFile.Name)} = '{dataFilesPath}ApplicationName1.exe'")
                    .Where(InformationType.DataFiles, $"{nameof(DataFile.Name)} = '{dataFilesPath}ApplicationName2.exe'")
                    .Where(InformationType.DataFiles, $"where {nameof(DataFile.Name)} = '{dataFilesPath}ApplicationName3.exe'")
                    .Where(InformationType.DataFiles, $"where {nameof(DataFile.Name)} = '{dataFilesPath}subpath\\ApplicationName1.exe'")
                    .Where(InformationType.DataFiles, $"{nameof(DataFile.Name)} = '{dataFilesPath}subpath\\ApplicationName2.exe'")
                    .Where(InformationType.DataFiles, $"{nameof(DataFile.Name)} = '{dataFilesPath}subpath\\Library.dll'")                
                    .Where(InformationType.DataFiles, $@"{nameof(DataFile.Path)} = '\\Program Files (x86)\\Notepad++\\'")                
                    .Where(InformationType.PNPEntities, $"{nameof(PNPEntity.Description)} LIKE '% PCI %'")
                    .GetDevicesAsync(hostNames, cancellationToken)
                    .ConfigureAwait(false);
                    
var performanceSummary = deviceCollection.Summarize();

Information Categories

All,
Software,
InternalHardware,
OperatingSystem,
ExternalHardware,
System,
User,
Application,
Network,
Configuration,
PNP,
DataFiles

Information Types

All,
BaseBoard,
BIOS,
ComputerSystem,
DataFiles,
Desktops,
Disks,
DiskDrives,
DiskPartitions,
Environments,
LocalTime,
NetworkAdapters,
NetworkAdapterConfigurations,
OperatingSystem,
PhysicalMemories,
PNPEntities,
PNPSignedDrivers,
Printers,
PrinterConfigurations,
Processes,
Processor,
Products,
QuickFixEngineerings,
SerialPorts,
SerialPortConfigurations,
Services,
SoftwareLicensingService,
TimeZone,
VideoControllers,
Volumes,
WindowsScore

Credential Provider

This is an inbuilt CredentialsProvider. This can be customized to have anything provide the credential information as long as it implements the interface "ICredentialsProvider".

public class CredentialsProvider : ICredentialsProvider
{
    private readonly string _user;
    private readonly string _pass;
    private readonly string _domain;

    public CredentialsProvider(string user, string pass, string domain = null)
    {
        _user = user;
        _pass = pass;
        _domain = domain;
    }

    public async Task<WMIConnectionOption> GetWMIConnectionOptionAsync(string hostName)
    {
        return await Task.Run(() => new WMIConnectionOption(hostName, _domain, _user, _pass)).ConfigureAwait(false);
    }

    public async Task<WMIConnectionOption> GetWMIConnectionOptionAsync(string hostName, string domain)
    {
        return await Task.Run(() => new WMIConnectionOption(hostName, domain, _user, _pass)).ConfigureAwait(false);
    }
}

Logging

To make it possible to catch log messages asynchronously this will be handled through events. Available events to subscribe for logging:

    public static event EventHandler<EventArgs<string>> OnConnectionMessage;
    public static event EventHandler<EventArgs<string>> OnDebugMessage;
    public static event EventHandler<EventArgs<string>> OnInformationMessage;
    public static event EventHandler<EventArgs<string>> OnWarningMessage;
    public static event EventHandler<EventArgs<string>> OnErrorMessage;
    public static event EventHandler<EventArgs<WMIGeneralException>> OnExceptionMessage;
    public static event EventHandler<EventArgs<OperationCanceledException>> OnTaskIncompleted;

OnConnectionMessage will publish messages about connection on hosts.

OnInformationMessage will publish messages about fetched properties from hosts.

OnWarningMessage will publish messages about warnings.

OnExceptionMessage will publish WMI exceptions.

OnTaskIncompleted will publish task cancelled exceptions.

OnDebugMessage not yet implemented.

OnErrorMessage not yet implemented.

Sample Usage:

LogEventHandler.OnInformationMessage += LogEventHandler_OnInformationMessage;
private static void LogEventHandler_OnInformationMessage(object sender, EventArgs<string> eventArgs)
{
    Console.WriteLine(eventArgs.Object);
}
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.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.

2.0.2 - Moved to org