Skip to content

Commit 7f15f91

Browse files
committed
Temps (Windows): dirty support
Note: https://stackoverflow.com/a/17083409
1 parent c570c5b commit 7f15f91

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ elseif(WIN32)
519519
src/detection/swap/swap_windows.cpp
520520
src/detection/terminalfont/terminalfont_windows.c
521521
src/detection/terminalshell/terminalshell_windows.cpp
522+
src/detection/temps/temps_windows.cpp
522523
src/detection/uptime/uptime_windows.c
523524
src/detection/users/users_windows.c
524525
src/detection/wifi/wifi_windows.c

src/detection/cpu/cpu_windows.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "cpu.h"
2+
#include "detection/temps/temps_windows.h"
23
#include "util/windows/registry.h"
34
#include "util/mallocHelper.h"
45

@@ -46,4 +47,7 @@ void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu)
4647

4748
ffRegReadStrbuf(hKey, L"ProcessorNameString", &cpu->name, NULL);
4849
ffRegReadStrbuf(hKey, L"VendorIdentifier", &cpu->vendor, NULL);
50+
51+
if(instance->config.cpuTemp)
52+
ffDetectSmbiosTemp(&cpu->temperature, NULL);
4953
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
extern "C"
2+
{
3+
#include "temps_windows.h"
4+
}
5+
#include "util/windows/wmi.hpp"
6+
7+
extern "C"
8+
const char* ffDetectSmbiosTemp(double* current, double* critical)
9+
{
10+
// Requires Administrator priviledges
11+
// https://wutils.com/wmi/root/wmi/msacpi_thermalzonetemperature/#properties
12+
FFWmiQuery query(L"SELECT CurrentTemperature, CriticalTripPoint FROM MSAcpi_ThermalZoneTemperature WHERE Active = TRUE", nullptr, FFWmiNamespace::WMI);
13+
if(!query)
14+
return "Query WMI service failed";
15+
16+
if(FFWmiRecord record = query.next())
17+
{
18+
if (current && record.getReal(L"CurrentTemperature", current)) // In tenth of degrees Kelvin
19+
*current = *current / 10 - 273.15;
20+
if (critical && record.getReal(L"CriticalTripPoint", critical)) // In tenth of degrees Kelvin
21+
*critical = *critical / 10 - 273.15;
22+
}
23+
24+
return "No WMI result returned";
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
#ifndef FF_INCLUDED_detection_temps_windows
4+
#define FF_INCLUDED_detection_temps_windows
5+
6+
const char* ffDetectSmbiosTemp(double* current, double* critical);
7+
8+
#endif

0 commit comments

Comments
 (0)