14 unstable releases (6 breaking)

0.7.0 Nov 7, 2020
0.6.0 Sep 14, 2020
0.5.0 Jul 21, 2020
0.4.6 Oct 17, 2019
0.4.4 Jun 11, 2019

#11 in Windows APIs

Download history 145/week @ 2020-08-11 246/week @ 2020-08-18 160/week @ 2020-08-25 113/week @ 2020-09-01 220/week @ 2020-09-08 120/week @ 2020-09-15 89/week @ 2020-09-22 85/week @ 2020-09-29 112/week @ 2020-10-06 101/week @ 2020-10-13 156/week @ 2020-10-20 161/week @ 2020-10-27 141/week @ 2020-11-03 116/week @ 2020-11-10 127/week @ 2020-11-17 146/week @ 2020-11-24

606 downloads per month

MIT/Apache

99KB
2.5K SLoC

wmi

Build Status crates.io docs.rs

WMI (Windows Management Instrumentation) crate for rust.

# Cargo.toml
[dependencies]
wmi = "0.7"

Examples

Queries can be deserialized info a free-form HashMap or a struct:

#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
    
use serde::Deserialize;
use wmi::{COMLibrary, Variant, WMIConnection, WMIDateTime};
use std::collections::HashMap;

fn main() -> Result<(), Box<dyn std::error::Error>>  {
    let com_con = COMLibrary::new()?;
    let wmi_con = WMIConnection::new(com_con.into())?;
    
    let results: Vec<HashMap<String, Variant>> = wmi_con.raw_query("SELECT * FROM Win32_OperatingSystem")?;
    
    for os in results {
        println!("{:#?}", os);
    }
    
    #[derive(Deserialize, Debug)]
    struct Win32_OperatingSystem {
        Caption: String,
        Name: String,
        CurrentTimeZone: i16,
        Debug: bool,
        EncryptionLevel: u32,
        ForegroundApplicationBoost: u8,
        LastBootUpTime: WMIDateTime,
    }
    
    let results: Vec<Win32_OperatingSystem> = wmi_con.query()?;
    
    for os in results {
        println!("{:#?}", os);
    }
    
    Ok(())
}

License

The wmi crate is licensed under either of

Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

Dependencies

~0–470KB