Crates.io | query-wmi |
lib.rs | query-wmi |
version | 1.1.3 |
source | src |
created_at | 2023-02-20 11:04:27.771215 |
updated_at | 2023-02-21 05:59:52.012569 |
description | A crate to query WMI classes in Windows OS |
homepage | https://github.com/SubconsciousCompute/query-wmi |
repository | https://github.com/SubconsciousCompute/query-wmi |
max_upload_size | |
id | 789740 |
size | 70,357 |
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(())
}
type Query = Vec<HashMap<String, Variant>>
.
String
is the name of the returned struct field with Variant
being an enum type.
The subsections were defined according to WMI Tasks for Scripts and Applications, you can find more classes here.
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)?);
You can also replace CLASS_NAME
with a query like CLASS_NAME where SOME_CONDITION=VALUE
See WQL Operators