-
Notifications
You must be signed in to change notification settings - Fork 122
/
SetandQueryTimerRes.ps1
37 lines (30 loc) · 1.55 KB
/
SetandQueryTimerRes.ps1
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
# Basic example of using powershell for setting or querying the windows timer resolution value
# using .NET functions by importing the ntdll.dll functions NtSetTimerResolution, NtQueryTimerResolution
#
# You can use this function to micro-increment timer resolution
# See https://github.com/djdallmann/GamingPCSetup/blob/master/RESEARCH/FINDINGS/timermicroadjust.txt
#
# Author: djdallmann
# https://github.com/djdallmann/GamingPCSetup
# Happy Scripting :D
$ntqtrmin = $null
$ntqtrmax = $null
$ntqtrcur = $null
#The resolution you want
$ntdesiredres = 6000
$ntsetres = $true
$ntcurrentres = 156250
#Import the functions from dll
$MethodDefinition = @’
[DllImport("ntdll.dll", SetLastError=true)]
public static extern NtStatus NtQueryTimerResolution(out uint MinimumResolution, out uint MaximumResolution, out uint ActualResolution);
[DllImport("ntdll.dll", SetLastError=true)]
public static extern int NtSetTimerResolution(int DesiredResolution, bool SetResolution, out int CurrentResolution );
‘@
$NtStatus = Add-Type -MemberDefinition $MethodDefinition -Name 'NtStatus' -Namespace 'Win32' -PassThru
#Set the timer resolution using the variables at the top
$ret1 = [Win32.NtStatus]::NtSetTimerResolution($ntdesiredres,$ntsetres,[ref]$ntcurrentres)
#Query the timer resolution and store them in the variables ntqtrmin, ntqtrmax and ntqtrcur
[Win32.NtStatus]::NtQueryTimerResolution([ref]$ntqtrmin, [ref]$ntqtrmax, [ref]$ntqtrcur)
#Print the timer resolution values
Write-Host "Current Timer Res: $ntqtrcur `r`nTimer Res Minimum: $ntqtrmin `r`nTimer Res Maximum: $ntqtrmax `r`n"