Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JonasJore opened this issue Feb 21, 2022 · 8 comments
Open

Comments

@JonasJore
Copy link

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
Copy link
Owner

valpackett commented Feb 22, 2022

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
Copy link

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
Copy link
Contributor

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
Copy link

Hey @adumbidiot,

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

Thanks a lot,
HackingAll

@adumbidiot
Copy link
Contributor

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

@M0ttii
Copy link

M0ttii commented Jun 27, 2023

@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
Copy link
Contributor

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants