query_wmi

Rust Crates.io docs.rs

A crate to query WMI classes in windows

https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-start-page

Windows Management Instrumentation (WMI) is the infrastructure for management data and operations on Windows-based operating systems. You can write WMI scripts or applications to automate administrative tasks on remote computers, but WMI also supplies management data to other parts of the operating system and products—for example, System Center Operations Manager (formerly Microsoft Operations Manager (MOM)), or Windows Remote Management (WinRM). Usage:

```rust use querywmi::{COMLibrary, Variant, WMIConnection}; use querywmi::computerhardware::{ getWin32CDROMDrive, getWin32ComputerSystem, getWin32PCMCIAController, getWin32PnPEntity, getWin32Processor, getWin32SystemEnclosure, getWin32TapeDrive, getWin32USBHub, }; use querywmi::operatingsystems::getWin32_OperatingSystem;

fn main() -> Result<(), Box> { let comcon = COMLibrary::new()?; dbg!(getWin32OperatingSystem(comcon)?); dbg!(getWin32CDROMDrive(comcon)?); dbg!(getWin32ComputerSystem(comcon)?); dbg!(getWin32PCMCIAController(comcon)?); dbg!(getWin32PnPEntity(comcon)?); dbg!(getWin32Processor(comcon)?); dbg!(getWin32SystemEnclosure(comcon)?); dbg!(getWin32USBHub(comcon)?); dbg!(getWin32TapeDrive(comcon)?); Ok(()) } ```

Return type

type Query = Vec<HashMap<String, Variant>>.

String is the name of the returned struct field with Variant being an enum type.

Currently included queries:

The subsections were defined according to WMI Tasks for Scripts and Applications, you can find more classes here.

Accounts and Domains

Computer Hardware

Computer Software

Dates and Times

Desktop Management

Disks and File Systems

Event Logs

Files and Folders

Networking

Operating Systems

Performance Monitoring

Processes

Printers and Printing

Registry

Scheduled Tasks

Services

Building your own class queries

You can use the provided wmi macro to make your own queries:

```rust

![allow(nonsnakecase)]

use querywmi::wmi; use querywmi::Query; use paste::paste; use std::collections::HashMap; use querywmi::COMLibrary; use querywmi::{Variant, WMIConnection};

// this creates the function get_CLASS_NAME() wmi! { /// Documentation CLASSNAME, r"pathto_namespace" }

// calling it let comcon = COMLibrary::new() ?; dbg!(getCLASSNAME(comcon)?); ```

Building your own queries

You can also replace CLASS_NAME with a query like CLASS_NAME where SOME_CONDITION=VALUE

See WQL Operators