valpackett / systemstat

Rust library for getting system information | also on https://codeberg.org/valpackett/systemstat
https://crates.io/crates/systemstat
The Unlicense
616 stars 71 forks source link

cpu_temp returns the error message: "Not supported" on Windows 10 #94

Open JonasJore opened 2 years ago

JonasJore commented 2 years ago

Upon running cargo run from terminal the call to system.cpu_temp() returns the error message: Not supported for Windows 10. Even though it says on the crates.io page that there should be support for Windows.

Attached code where i tried to get cpu_temp:

extern crate systemstat;

use std::thread;
use std::time::Duration;
use systemstat::{System, Platform, saturating_sub_bytes};

fn main() {
    let system = System::new();

    match system.cpu_temp() {
        Ok(cpu_temp) => println!("\nCPU temp: {}", cpu_temp),
        Err(ex) => println!("\nCPU temp: {}", ex) 
    }
}
valpackett commented 2 years ago

Support for $anything does not mean everything is supported on that platform, just that something is. There is no platform currently for which everything is supported. PRs welcome.

HackingAllYT commented 2 years ago

Hi!

This problem is still exists, any idea how to make it work on windows 10?

If I need to use another crate or something it will fix for my case.

Thanks a lot, HackingAll

adumbidiot commented 2 years ago

I’m fairly certain the best way to get this information on Windows is through WMI and needs admin privileges, which limits its usability.

HackingAllYT commented 2 years ago

Hey @adumbidiot,

Do you know with it is the crate to connect with the WMI?

Thanks a lot, HackingAll

adumbidiot commented 2 years ago

https://docs.rs/wmi/latest/wmi/ is the only one I know of.

M0ttii commented 1 year ago

@HackingAllYT @adumbidiot doing it with WMI will not work on most devices due to lack of support from cpu manufactures. The only library which reliably does the job is OpenHardwareMonitor (LibreHardwareMonitor is the continued fork). It directly accesses the WinRing0 driver and reads out the MSR CPU register. Doing it that way will work. There are two ways how you can do it in rust: LibreHardwareMonitor is written in C# but uses C-Bindings to access the WinRing0 driver. You can also do this in Rust. Secondly you can use the winRing0 crate for rust. Unfortunately it's no longer maintained and not production ready. But i managed to get the cpu_temp on windows with this crate.

https://github.com/LibreHardwareMonitor/LibreHardwareMonitor/tree/master/WinRing0 https://alex-dow.github.io/winRing0-rs/

adumbidiot commented 1 year ago

While installing a custom driver would probably give better results, it’s more invasive and can’t really be incorporated into a library like this one which is more focused on asking the OS for info instead of bypassing it. Furthermore, driver signing on Windows is pretty difficult, and I recall there being quite a few security vulnerabilities with the WinRing0 driver. Applications that can function with imprecise or missing temperature data probably should prefer WMI, since I think that’s the most reliable source of temperature info from the OS. Temperature retrieval on Windows is quite a mess.

CarterLi commented 7 months ago

WMI supports only MSAcpi_ThermalZoneTemperature. Thermal zone is somewhere on the motherboard ( different OEM uses different places ), but not CPU.