Macchina-CLI / libmacchina

A library providing access to all sorts of system information.
https://crates.io/crates/libmacchina
MIT License
68 stars 20 forks source link

`os_name()` only works once on Windows #139

Closed Gobidev closed 1 year ago

Gobidev commented 1 year ago

Calling os_name() on Windows only returns the correct value the first time it is called in a program. Using a new readout does not help.

The follwing program

use libmacchina::*;

fn main() {
    use libmacchina::traits::{GeneralReadout as _};

    let general_readout = GeneralReadout::new();
    let _ = dbg!(general_readout.os_name());
    let _ = dbg!(general_readout.os_name());

    let general_readout = GeneralReadout::new();
    let _ = dbg!(general_readout.os_name());
}

produces this output:

[src\main.rs:7] general_readout.os_name() = Ok(
    "Microsoft Windows 11 Pro",
)
[src\main.rs:8] general_readout.os_name() = Err(
    Other(
        "HRESULT Call failed with: 0x80010119",
    ),
)
[src\main.rs:11] general_readout.os_name() = Err(
    Other(
        "HRESULT Call failed with: 0x80010119",
    ),
)

The expected output would be:

[src\main.rs:7] general_readout.os_name() = Ok(
    "Microsoft Windows 11 Pro",
)
[src\main.rs:8] general_readout.os_name() = Ok(
    "Microsoft Windows 11 Pro",
)
[src\main.rs:11] general_readout.os_name() = Ok(
    "Microsoft Windows 11 Pro",
)
grtcdr commented 1 year ago

I don't know the first thing about Windows internals, maybe @FantasyTeddy can help us with this one?

FantasyTeddy commented 1 year ago

Good catch! I can reproduce this error and it seems to be related to this issue: ohadravid/wmi-rs#37 Let me see if I can fix this.

Gobidev commented 1 year ago

Fixed in #143