-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathSetTimerResolution.cpp
50 lines (37 loc) · 1.65 KB
/
SetTimerResolution.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <windows.h>
typedef NTSTATUS(CALLBACK *NTQUERYTIMERRESOLUTION)(
OUT PULONG MinimumResolution,
OUT PULONG MaximumResolution,
OUT PULONG CurrentResolutionolution);
typedef NTSTATUS(CALLBACK *NTSETTIMERRESOLUTION)(
IN ULONG DesiredResolution,
IN BOOLEAN SetResolution,
OUT PULONG CurrentResolutionolution);
int main() {
// FreeConsole(); // hides console
ULONG MinimumResolution, MaximumResolution, CurrentResolution;
PROCESS_POWER_THROTTLING_STATE PowerThrottling;
HMODULE hNtDll = LoadLibrary(L"NtDll.dll");
if (!hNtDll) {
printf("LoadLibrary failed");
return 1;
}
NTQUERYTIMERRESOLUTION NtQueryTimerResolution = (NTQUERYTIMERRESOLUTION)GetProcAddress(hNtDll, "NtQueryTimerResolution");
NTSETTIMERRESOLUTION NtSetTimerResolution = (NTSETTIMERRESOLUTION)GetProcAddress(hNtDll, "NtSetTimerResolution");
RtlZeroMemory(&PowerThrottling, sizeof(PowerThrottling));
PowerThrottling.Version = PROCESS_POWER_THROTTLING_CURRENT_VERSION;
PowerThrottling.ControlMask = PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION;
PowerThrottling.StateMask = 0;
SetProcessInformation(GetCurrentProcess(), ProcessPowerThrottling, &PowerThrottling, sizeof(PowerThrottling));
if (NtQueryTimerResolution(&MinimumResolution, &MaximumResolution, &CurrentResolution)) {
printf("NtQueryTimerResolution failed");
return 1;
}
if (NtSetTimerResolution(MaximumResolution, true, &CurrentResolution)) {
printf("NtSetTimerResolution failed");
return 1;
}
printf("Resolution set to: %lfms", (double)CurrentResolution / 10000);
Sleep(INFINITE);
}