Mtf.Wmi 1.0.7

dotnet add package Mtf.Wmi --version 1.0.7                
NuGet\Install-Package Mtf.Wmi -Version 1.0.7                
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="Mtf.Wmi" Version="1.0.7" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Mtf.Wmi --version 1.0.7                
#r "nuget: Mtf.Wmi, 1.0.7"                
#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 Mtf.Wmi as a Cake Addin
#addin nuget:?package=Mtf.Wmi&version=1.0.7

// Install Mtf.Wmi as a Cake Tool
#tool nuget:?package=Mtf.Wmi&version=1.0.7                

Mtf.Wmi Library Documentation

Overview

The Mtf.Wmi library provides tools for executing WMI (Windows Management Instrumentation) queries on both local and remote computers, utilizing the Wmi class for querying system information. It includes capabilities for impersonation, secure password handling, and flexible query parameters. This document covers setup, class details, method descriptions, and usage examples for effective system management and monitoring in .NET applications.

Installation

To install the Mtf.Wmi package, follow these steps:

  1. Add Package: Open the terminal in your project directory and run:

    dotnet add package Mtf.Wmi
    
  2. Include the Namespace: Add the Mtf.WmiHelper namespace at the beginning of your code file:

    using Mtf.WmiHelper;
    

Class: Wmi

The Wmi class provides methods for WMI queries that can return data from various namespaces on Windows-based systems. It supports querying both local and remote systems, with options for handling authentication, impersonation, and secure passwords.

Methods

WmiGetObjects

WmiReaderResult WmiGetObjects(string queryString, string nameSpace)

Executes a basic WMI query on the local computer using default authentication settings.

  • Parameters:

    • queryString: A WMI query string, e.g., SELECT * FROM Win32_BaseBoard.
    • nameSpace: The WMI namespace to query, e.g., cimv2.
  • Returns: A WmiReaderResult containing the column names and query results.

WmiReaderResult WmiGetObjects(string queryString, string nameSpace, string computerName, ImpersonationLevel impersonationLevel, AuthenticationLevel authenticationLevel, bool enablePrivileges = false, string username = null, SecureString securePassword = null, string password = null, string authority = null, ManagementNamedValueCollection context = null)

Performs a WMI query on a specified computer with advanced options.

  • Parameters:

    • queryString: WMI query string, e.g., SELECT * FROM Win32_BaseBoard.
    • nameSpace: WMI namespace, e.g., cimv2.
    • computerName: Target computer, e.g., localhost.
    • impersonationLevel, authenticationLevel, enablePrivileges: Security and privilege settings.
    • username, securePassword, password: Authentication credentials.
    • authority, context: Optional settings for WMI management context.
  • Returns: A WmiReaderResult containing column names and data results from the query.

GetCommaSeparatedColumnNames

string GetCommaSeparatedColumnNames(string query)

Extracts column names from a WMI SELECT query string.

  • Parameters:

    • query: The WMI query string, beginning with SELECT.
  • Returns: A comma-separated string of column names extracted from the query.

Example Usage

using Mtf.WmiHelper;
using System.Security;
using System.Management;

public class WmiExample
{
    public void ExecuteQuery()
    {
        var securePassword = new SecureString();
        foreach (var ch in "password") securePassword.AppendChar(ch);

        // Basic query on local computer
        var result = Wmi.WmiGetObjects("SELECT * FROM Win32_BaseBoard", "cimv2");

        // Advanced query on a remote computer
        var remoteResult = Wmi.WmiGetObjects(
            "SELECT * FROM Win32_OperatingSystem",
            "cimv2",
            "RemoteComputerName",
            ImpersonationLevel.Impersonate,
            AuthenticationLevel.PacketPrivacy,
            enablePrivileges: true,
            username: "Administrator",
            securePassword: securePassword,
            context: new ManagementNamedValueCollection()
        );

        // Display results
        Console.WriteLine($"Columns: {result.ColumnNames}");
        foreach (var row in result.Rows)
        {
            Console.WriteLine(String.Join(", ", row));
        }
    }
}

Notes

  • Error Handling: Ensure exception handling for secure data transmission and network issues.
  • Security: Use secure passwords (SecureString) where possible to enhance security when accessing remote systems.
  • Logging and Monitoring: Consider integrating logging to capture WMI query performance and errors in production environments.

This documentation provides a solid foundation for managing and utilizing WMI queries within .NET applications, enabling efficient and secure system information retrieval across networked computers.

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 (1)

Showing the top 1 NuGet packages that depend on Mtf.Wmi:

Package Downloads
Mtf.Serial

Serial Port Devices. The library includes various serial devices, such as: - LuminaryMicroIcdiComPort - ConradRelayCard - SltWatchdog - CarTft - StretchUart - Pelco KBD300A Compatibility: - .NET Standard 2.0

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.7 99 11/2/2024
1.0.4 75 11/1/2024
1.0.3 67 11/1/2024
1.0.2 70 11/1/2024
1.0.1 67 11/1/2024
1.0.0 67 11/1/2024