Temps (Windows): dirty support

Note: https://stackoverflow.com/a/17083409
This commit is contained in:
李通洲 2023-02-23 21:31:33 +08:00
parent c570c5bf97
commit 7f15f91bd3
No known key found for this signature in database
GPG Key ID: 6E72B663408769DE
4 changed files with 38 additions and 0 deletions

View File

@ -519,6 +519,7 @@ elseif(WIN32)
src/detection/swap/swap_windows.cpp
src/detection/terminalfont/terminalfont_windows.c
src/detection/terminalshell/terminalshell_windows.cpp
src/detection/temps/temps_windows.cpp
src/detection/uptime/uptime_windows.c
src/detection/users/users_windows.c
src/detection/wifi/wifi_windows.c

View File

@ -1,4 +1,5 @@
#include "cpu.h"
#include "detection/temps/temps_windows.h"
#include "util/windows/registry.h"
#include "util/mallocHelper.h"
@ -46,4 +47,7 @@ void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu)
ffRegReadStrbuf(hKey, L"ProcessorNameString", &cpu->name, NULL);
ffRegReadStrbuf(hKey, L"VendorIdentifier", &cpu->vendor, NULL);
if(instance->config.cpuTemp)
ffDetectSmbiosTemp(&cpu->temperature, NULL);
}

View File

@ -0,0 +1,25 @@
extern "C"
{
#include "temps_windows.h"
}
#include "util/windows/wmi.hpp"
extern "C"
const char* ffDetectSmbiosTemp(double* current, double* critical)
{
// Requires Administrator priviledges
// https://wutils.com/wmi/root/wmi/msacpi_thermalzonetemperature/#properties
FFWmiQuery query(L"SELECT CurrentTemperature, CriticalTripPoint FROM MSAcpi_ThermalZoneTemperature WHERE Active = TRUE", nullptr, FFWmiNamespace::WMI);
if(!query)
return "Query WMI service failed";
if(FFWmiRecord record = query.next())
{
if (current && record.getReal(L"CurrentTemperature", current)) // In tenth of degrees Kelvin
*current = *current / 10 - 273.15;
if (critical && record.getReal(L"CriticalTripPoint", critical)) // In tenth of degrees Kelvin
*critical = *critical / 10 - 273.15;
}
return "No WMI result returned";
}

View File

@ -0,0 +1,8 @@
#pragma once
#ifndef FF_INCLUDED_detection_temps_windows
#define FF_INCLUDED_detection_temps_windows
const char* ffDetectSmbiosTemp(double* current, double* critical);
#endif