Skip to content

Commit

Permalink
Merge pull request #1 from sn99/master
Browse files Browse the repository at this point in the history
add documentation, update macro to have documentation and include accounts_and_domains
  • Loading branch information
sn99 authored Feb 20, 2023
2 parents 7e399a1 + 8af54f2 commit af4d288
Show file tree
Hide file tree
Showing 21 changed files with 1,321 additions and 54 deletions.
15 changes: 13 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
[package]
name = "query-wmi"
version = "0.1.0"
version = "1.0.0"
edition = "2021"
authors = ["sn99 <siddharthn.099@gmail.com>"]
description = "A crate to query WMI classes in Windows OS"
repository = "https://github.com/SubconsciousCompute/query-wmi"
homepage = "https://github.com/SubconsciousCompute/query-wmi"
keywords = ["wmi", "query", "windows", "win32", "com"]
readme = "README.md"
documentation = "https://docs.rs/query-wmi"
license = "AGPL-3.0-only"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
wmi = "0.11.4"
serde = "1.0.152"
paste = "1.0.11"
paste = "1.0.11"

[profile.release]
lto = true
codegen-units = 1
opt-level = 3
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

131 changes: 126 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# query_wmi

[![Rust](https://github.com/SubconsciousCompute/query-wmi/actions/workflows/rust.yml/badge.svg?branch=master)](https://github.com/SubconsciousCompute/query-wmi/actions/workflows/rust.yml)
[![Crates.io](https://img.shields.io/crates/v/query-wmi)](https://crates.io/crates/query-wmi)
[![docs.rs](https://img.shields.io/docsrs/query-wmi)](https://docs.rs/query-wmi/latest/query-wmi/)

A crate to query `WMI` classes in windows

https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-start-page
Expand All @@ -8,14 +12,16 @@ https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-start-page
> 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:
> Usage:
```rust
use query_wmi::computer_hardware::{
get_Win32_CDROMDrive, get_Win32_ComputerSystem, get_Win32_OperatingSystem,
get_Win32_PCMCIAController, get_Win32_PnPEntity, get_Win32_Processor,
get_Win32_SystemEnclosure, get_Win32_TapeDrive, get_Win32_USBHub,
};
use wmi::COMLibrary;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let com_con = COMLibrary::new()?;
dbg!(get_Win32_OperatingSystem(com_con)?);
Expand All @@ -31,8 +37,114 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
```

## Building your own queries
You can use the provided [`wmi`](crate::wmi) macro to make your own queries:
## 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](https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks-for-scripts-and-applications),
you can find more classes [here](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/operating-system-classes).

[Accounts and Domains](https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--accounts-and-domains)

- [Win32_ComputerSystem](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-computersystem)
- [Win32_Group](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-group)

[Computer Hardware](https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--computer-hardware)

- [Win32_CDROMDrive](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-cdromdrive)
- [Win32_ComputerSystem](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-computersystem)
- [Win32_PCMCIAController](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-pcmciacontroller)
- [Win32_PnPEntity](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-pnpentity)
- [Win32_PointingDevice](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-pointingdevice)
- [Win32_Processor](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-processor)
- [Win32_SystemEnclosure](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-systemenclosure)
- [Win32_USBHub](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/cimwin32a/win32-usbhub)
- [Win32_TapeDrive](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-tapedrive)

[Computer Software](https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--computer-software)

- [Win32_Product](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/aa394378(v=vs.85))

[Dates and Times](https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--dates-and-times)

- [Win32_LocalTime](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/wmitimepprov/win32-localtime)
- [Win32_TimeZone](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-timezone)

[Desktop Management](https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--desktop-management)

- [Win32_Desktop](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-desktop)
- [Win32_DesktopMonitor](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-desktopmonitor)
- [Win32_StartupCommand](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-startupcommand)

[Disks and File Systems](https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--disks-and-file-systems)

- [Win32_DiskQuota](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/wmipdskq/win32-diskquota)
- [Win32_VolumeChangeEvent](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-volumechangeevent)
- [Win32_LogicalDisk](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-logicaldisk)
- [Win32_MappedLogicalDisk](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-mappedlogicaldisk)
- [Win32_Volume](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/aa394515(v=vs.85))
- [Win32_DiskDrive](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-diskdrive)
- [Win32_DiskPartition](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-diskpartition)

[Event Logs](https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--event-logs)

- [Win32_NTLogEvent](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/eventlogprov/win32-ntlogevent)
- [Win32_NTEventlogFile](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/aa394225(v=vs.85))

[Files and Folders](https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--files-and-folders)

- [CIM_DataFile](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/cim-datafile)
- [Win32_Share](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-share)
- [Win32_Directory](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-directory)

[Networking](https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--networking)

- [Win32_NetworkAdapterConfiguration](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-networkadapterconfiguration)
- [Win32_NetworkAdapter](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-networkadapter)

[Operating Systems](https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--operating-systems)

- [Win32_OperatingSystem](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-operatingsystem)
- [Win32_QuickFixEngineering](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-quickfixengineering)
- [Win32_WindowsProductActivation](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/aa394520(v=vs.85))

[Performance Monitoring](https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--performance-monitoring)

- [Win32_Perf](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-perf)
- [Win32_PerfFormattedData](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-perfformatteddata)
- [Win32_PerfRawData](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-perfrawdata)

[Processes](https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--processes)

- [Win32_Process](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-process)
- [Win32_ProcessStartup](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-processstartup)

[Printers and Printing](https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--printers-and-printing)

- [Win32_Printer](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-printer)

[Registry](https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--registry)

- [Win32_Registry](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-registry)

[Scheduled Tasks](https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--scheduled-tasks)

- [Win32_ScheduledJob](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-scheduledjob)

[Services](https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--services)

- [Win32_Service](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-service)
- [Win32_DependentService](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-dependentservice)

## Building your own class queries

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

```rust
#![allow(non_snake_case)]

Expand All @@ -44,9 +156,18 @@ use query_wmi::COMLibrary;
use query_wmi::{Variant, WMIConnection};

// this creates the function `get_CLASS_NAME()`
wmi!(CLASS_NAME, r"path_to_namespace");
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](https://learn.microsoft.com/en-us/windows/win32/wmisdk/wql-operators)
19 changes: 19 additions & 0 deletions src/accounts_and_domains.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! <https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--accounts-and-domains>

#![allow(non_snake_case)]

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

wmi! {
/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-computersystem>
Win32_ComputerSystem, r"Root\CIMV2"
}
wmi! {
/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-group>
Win32_Group, r"Root\CIMV2"
}
50 changes: 38 additions & 12 deletions src/computer_hardware.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! <https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--computer-hardware>

#![allow(non_snake_case)]

use crate::wmi;
Expand All @@ -7,15 +9,39 @@ use crate::{Variant, WMIConnection};
use paste::paste;
use std::collections::HashMap;

// https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--computer-hardware

wmi!(Win32_OperatingSystem, r"Root\CIMV2");
wmi!(Win32_CDROMDrive, r"Root\CIMV2");
wmi!(Win32_ComputerSystem, r"Root\CIMV2");
wmi!(Win32_PCMCIAController, r"Root\CIMV2");
wmi!(Win32_PnPEntity, r"Root\CIMV2");
wmi!(Win32_PointingDevice, r"Root\CIMV2");
wmi!(Win32_Processor, r"Root\CIMV2");
wmi!(Win32_SystemEnclosure, r"Root\CIMV2");
wmi!(Win32_USBHub, r"Root\CIMV2");
wmi!(Win32_TapeDrive, r"Root\CIMV2");
wmi! {
/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-cdromdrive>
Win32_CDROMDrive, r"Root\CIMV2"
}
wmi! {
/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-computersystem>
Win32_ComputerSystem, r"Root\CIMV2"
}
wmi! {
/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-pcmciacontroller>
Win32_PCMCIAController, r"Root\CIMV2"
}
wmi! {
/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-pnpentity>
Win32_PnPEntity, r"Root\CIMV2"
}
wmi! {
/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-pointingdevice>
Win32_PointingDevice, r"Root\CIMV2"
}
wmi! {
/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-processor>
Win32_Processor, r"Root\CIMV2"
}
wmi! {
/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-systemenclosure>
Win32_SystemEnclosure, r"Root\CIMV2"
}
wmi! {
/// <https://learn.microsoft.com/en-us/previous-versions/windows/desktop/cimwin32a/win32-usbhub>
Win32_USBHub, r"Root\CIMV2"
}
wmi! {
/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-tapedrive>
Win32_TapeDrive, r"Root\CIMV2"
}
9 changes: 6 additions & 3 deletions src/computer_software.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! <https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--computer-software>

#![allow(non_snake_case)]

use crate::wmi;
Expand All @@ -7,6 +9,7 @@ use crate::{Variant, WMIConnection};
use paste::paste;
use std::collections::HashMap;

// https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--computer-software

wmi!(Win32_Product, r"Root\CIMV2");
wmi! {
/// <https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/aa394378(v=vs.85)>
Win32_Product, r"Root\CIMV2"
}
14 changes: 10 additions & 4 deletions src/date_and_times.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! <https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--dates-and-times>

#![allow(non_snake_case)]

use crate::wmi;
Expand All @@ -7,7 +9,11 @@ use crate::{Variant, WMIConnection};
use paste::paste;
use std::collections::HashMap;

// https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--dates-and-times

wmi!(Win32_LocalTime, r"Root\CIMV2");
wmi!(Win32_TimeZone, r"Root\CIMV2");
wmi! {
/// <https://learn.microsoft.com/en-us/previous-versions/windows/desktop/wmitimepprov/win32-localtime>
Win32_LocalTime, r"Root\CIMV2"
}
wmi! {
/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-timezone>
Win32_TimeZone, r"Root\CIMV2"
}
24 changes: 24 additions & 0 deletions src/desktop_management.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//! <https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--desktop-management>

#![allow(non_snake_case)]

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

wmi! {
/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-desktop>
Win32_Desktop, r"Root\CIMV2"
}
wmi! {
/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-desktopmonitor>
Win32_DesktopMonitor, r"Root\CIMV2"
}

wmi! {
/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-startupcommand>
Win32_StartupCommand, r"Root\CIMV2"
}
42 changes: 42 additions & 0 deletions src/disks_and_file_systems.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//! <https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-tasks--disks-and-file-systems>

#![allow(non_snake_case)]

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

wmi! {
/// <https://learn.microsoft.com/en-us/previous-versions/windows/desktop/wmipdskq/win32-diskquota>
Win32_DiskQuota, r"Root\CIMV2"
}
wmi! {
/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-volumechangeevent>
Win32_VolumeChangeEvent, r"Root\CIMV2"
}

wmi! {
/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-logicaldisk>
Win32_LogicalDisk, r"Root\CIMV2"
}
wmi! {
/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-mappedlogicaldisk>
Win32_MappedLogicalDisk, r"Root\CIMV2"
}
wmi! {
/// <https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/aa394515(v=vs.85)>
Win32_Volume, r"Root\CIMV2"
}

wmi! {
/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-diskdrive>
Win32_DiskDrive, r"Root\CIMV2"
}

wmi! {
/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-diskpartition>
Win32_DiskPartition, r"Root\CIMV2"
}
Loading

0 comments on commit af4d288

Please # to comment.