query-wmi

Crates.ioquery-wmi
lib.rsquery-wmi
version1.1.3
sourcesrc
created_at2023-02-20 11:04:27.771215
updated_at2023-02-21 05:59:52.012569
descriptionA crate to query WMI classes in Windows OS
homepagehttps://github.com/SubconsciousCompute/query-wmi
repositoryhttps://github.com/SubconsciousCompute/query-wmi
max_upload_size
id789740
size70,357
Dilawar Singh (dilawar)

documentation

https://docs.rs/query-wmi

README

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:

use query_wmi::{COMLibrary, Variant, WMIConnection};
use query_wmi::computer_hardware::{
    get_Win32_CDROMDrive, get_Win32_ComputerSystem,
    get_Win32_PCMCIAController, get_Win32_PnPEntity, get_Win32_Processor,
    get_Win32_SystemEnclosure, get_Win32_TapeDrive, get_Win32_USBHub,
};
use query_wmi::operating_systems::get_Win32_OperatingSystem;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let com_con = COMLibrary::new()?;
    dbg!(get_Win32_OperatingSystem(com_con)?);
    dbg!(get_Win32_CDROMDrive(com_con)?);
    dbg!(get_Win32_ComputerSystem(com_con)?);
    dbg!(get_Win32_PCMCIAController(com_con)?);
    dbg!(get_Win32_PnPEntity(com_con)?);
    dbg!(get_Win32_Processor(com_con)?);
    dbg!(get_Win32_SystemEnclosure(com_con)?);
    dbg!(get_Win32_USBHub(com_con)?);
    dbg!(get_Win32_TapeDrive(com_con)?);
    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:

#![allow(non_snake_case)]

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

// this creates the function `get_CLASS_NAME()`
wmi! {
    /// Documentation
    CLASS_NAME, r"path_to_namespace"
}

// calling it
let com_con = COMLibrary::new() ?;
dbg!(get_CLASS_NAME(com_con)?);

Building your own queries

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

See WQL Operators

Commit count: 32

cargo fmt