-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRepairTweaks.ps1
324 lines (300 loc) · 14.5 KB
/
RepairTweaks.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#repair bad tweaks by zoic
If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')) {
Start-Process PowerShell.exe -ArgumentList ("-NoProfile -ExecutionPolicy Bypass -File `"{0}`"" -f $PSCommandPath) -Verb RunAs
Exit
}
#global vars
$Global:currentControlSet = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet'
$Global:controlSet001 = 'HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001'
#function to check for bad tweaks returns hastable
function checkTweaks {
#hashtable for tweaks
$tweaksTable = @{}
$tweaks = @(
'Svc Split Threshold',
'Bcdedit',
'Timer Resolution',
'Win32PrioritySeparation',
'Tcp Auto-Tuning',
'Prefetch',
'Windows Error Reporting',
'Sysmain Service',
'Ordinary DPCs',
'Spectre Meltdown Mitigations',
'HPET',
'Mouse Keyboard Queue Size',
'Csrss Priority'
)
#add to hashtable
foreach ($tweak in $tweaks) {
$tweaksTable[$tweak] = $false
}
#check svc split threshold
$svcSplitCurrent = Get-ItemPropertyValue -Path "registry::$currentControlSet\Control" -Name 'SvcHostSplitThresholdInKB'
$svcSplitControl = Get-ItemPropertyValue -Path "registry::$controlSet001\Control" -Name 'SvcHostSplitThresholdInKB'
if ($svcSplitCurrent -ne 3670016 -or $svcSplitControl -ne 3670016) {
$tweaksTable['Svc Split Threshold'] = $true
}
#check bcdedit tweaks
$bcd = bcdedit.exe
#regEX with | for 'or'
$values = 'useplatformclock|disabledynamictick|useplatformtick|tscsyncpolicy'
if ($bcd -match $values) {
$tweaksTable['Bcdedit'] = $true
}
#check for timer res, timer res service, islc
#global scope for proper cleanup later
$Global:timerRes = Get-Process -Name TimerResolution -ErrorAction SilentlyContinue
$Global:timerResService = Get-Service -Name 'STR', 'Set Timer Resolution Service' -ErrorAction SilentlyContinue
$Global:islc = Get-Process -Name 'Intelligent standby list cleaner ISLC' -ErrorAction SilentlyContinue
if ($timerRes -or $timerResService -or $islc) {
$tweaksTable['Timer Resolution'] = $true
}
#check win32priority
$controlSetP = Get-ItemPropertyValue -Path "registry::$controlSet001\Control\PriorityControl" -Name 'Win32PrioritySeparation'
$currentControlSetP = Get-ItemPropertyValue -Path "registry::$currentControlSet\Control\PriorityControl" -Name 'Win32PrioritySeparation'
if ($currentControlSetP -ne 38 -or $controlSetP -ne 38) {
$tweaksTable['Win32PrioritySeparation'] = $true
}
#check auto-tuning
$autotuning = netsh interface tcp show global | Select-String 'Receive Window Auto-Tuning Level'
if ($autotuning -notlike '*normal*') {
$tweaksTable['Tcp Auto-Tuning'] = $true
}
#check prefetch
$prefetchCurrent = Get-ItemPropertyValue -Path "registry::$currentControlSet\Control\Session Manager\Memory Management\PrefetchParameters" -Name 'EnablePrefetcher'
$prefetchControl = Get-ItemPropertyValue -Path "registry::$controlSet001\Control\Session Manager\Memory Management\PrefetchParameters" -Name 'EnablePrefetcher'
if ($prefetchCurrent -ne 3 -or $prefetchControl -ne 3) {
$tweaksTable['Prefetch'] = $true
}
#check sysmain service (superfetch)
$start = (Get-Service -Name SysMain).StartType
if ($start -ne 'Automatic') {
$tweaksTable['Sysmain Service'] = $true
}
#check ordinary dpcs
$currentDpc = (Get-ItemProperty -Path "registry::$currentControlSet\Control\Session Manager\kernel").ThreadDpcEnable
$controlDpc = (Get-ItemProperty -Path "registry::$controlSet001\Control\Session Manager\kernel").ThreadDpcEnable
if ($currentDpc -eq 0 -or $controlDpc -eq 0) {
$tweaksTable['Ordinary DPCs'] = $true
}
#windows error reporting
$svcStart = (Get-Service -Name WerSvc).StartType
$policy = (Get-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Windows Error Reporting' -ErrorAction SilentlyContinue).Disabled
if ($svcStart -ne 'Manual' -or $policy -eq 1) {
$tweaksTable['Windows Error Reporting'] = $true
}
#check spectre and meltdown mitigations
$overrideCurrent = (Get-ItemProperty -Path "registry::$currentControlSet\Control\Session Manager\Memory Management").FeatureSettingsOverride
$overrideMaskCurrent = (Get-ItemProperty -Path "registry::$currentControlSet\Control\Session Manager\Memory Management").FeatureSettingsOverrideMask
$overrideControl = (Get-ItemProperty -Path "registry::$controlSet001\Control\Session Manager\Memory Management").FeatureSettingsOverride
$overrideMaskControl = (Get-ItemProperty -Path "registry::$controlSet001\Control\Session Manager\Memory Management").FeatureSettingsOverrideMask
if ($overrideCurrent -eq 3 -or $overrideMaskCurrent -eq 3 -or $overrideControl -eq 3 -or $overrideMaskControl -eq 3) {
$tweaksTable['Spectre Meltdown Mitigations'] = $true
}
#check High precision event timer
$status = (Get-PnpDevice -FriendlyName 'High precision event timer').Status
if ($status -ne 'OK') {
$tweaksTable['HPET'] = $true
}
#check mouse and keyboard queue size
#use try and catch when value doesnt exist
try {
$keyboardCurrent = Get-ItemPropertyValue -Path "registry::$currentControlSet\Services\kbdclass\Parameters" -Name 'KeyboardDataQueueSize' -ErrorAction SilentlyContinue
}
catch {
#hide error
}
try {
$mouseCurrent = Get-ItemPropertyValue -Path "registry::$currentControlSet\Services\mouclass\Parameters" -Name 'MouseDataQueueSize' -ErrorAction SilentlyContinue
}
catch {
#hide error
}
try {
$keyboardControl = Get-ItemPropertyValue -Path "registry::$controlSet001\Services\kbdclass\Parameters" -Name 'KeyboardDataQueueSize' -ErrorAction SilentlyContinue
}
catch {
#hide error
}
try {
$mouseControl = Get-ItemPropertyValue -Path "registry::$controlSet001\Services\mouclass\Parameters" -Name 'MouseDataQueueSize' -ErrorAction SilentlyContinue
}
catch {
#hide error
}
#if value is null that is fine too (default value 100)
if ($keyboardCurrent) {
if ($keyboardCurrent -ne 100) {
$tweaksTable['Mouse Keyboard Queue Size'] = $true
}
}
if ($mouseCurrent) {
if ($mouseCurrent -ne 100) {
$tweaksTable['Mouse Keyboard Queue Size'] = $true
}
}
if ($keyboardControl) {
if ($keyboardControl -ne 100) {
$tweaksTable['Mouse Keyboard Queue Size'] = $true
}
}
if ($mouseControl) {
if ($mouseControl -ne 100) {
$tweaksTable['Mouse Keyboard Queue Size'] = $true
}
}
#check csrss priority
if (Test-Path -Path 'registry::HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\csrss.exe\PerfOptions' -ErrorAction SilentlyContinue) {
$tweaksTable['Csrss Priority'] = $true
}
return $tweaksTable
}
#pass string array
function repairTweaks($tweakNames) {
foreach ($tweak in $tweakNames) {
#repair superfetch
if ($tweak -eq 'Sysmain Service') {
Set-Service -Name SysMain -StartupType Automatic
}
#repair threaded dpcs
if ($tweak -eq 'Ordinary DPCs') {
Remove-ItemProperty -Path "registry::$currentControlSet\Control\Session Manager\kernel" -Name ThreadDpcEnable -Force -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "registry::$controlSet001\Control\Session Manager\kernel" -Name ThreadDpcEnable -Force -ErrorAction SilentlyContinue
}
#repair hpet
if ($tweak -eq 'HPET') {
Get-PnpDevice -FriendlyName 'High precision event timer' | Enable-PnpDevice -Confirm:$false
}
#repair mouse keyboard queue size
if ($tweak -eq 'Mouse Keyboard Queue Size') {
Reg.exe add 'HKLM\SYSTEM\CurrentControlSet\Services\kbdclass\Parameters' /v 'KeyboardDataQueueSize' /t REG_DWORD /d '100' /f *>$null
Reg.exe add 'HKLM\SYSTEM\ControlSet001\Services\kbdclass\Parameters' /v 'KeyboardDataQueueSize' /t REG_DWORD /d '100' /f *>$null
Reg.exe add 'HKLM\SYSTEM\CurrentControlSet\Services\mouclass\Parameters' /v 'KeyboardDataQueueSize' /t REG_DWORD /d '100' /f *>$null
Reg.exe add 'HKLM\SYSTEM\ControlSet001\Services\mouclass\Parameters' /v 'KeyboardDataQueueSize' /t REG_DWORD /d '100' /f *>$null
}
#repair timer res
if ($tweak -eq 'Timer Resolution') {
#cleanup timer res depending on which is being used
if ($timerRes) {
$filePath = (Get-Process -Name TimerResolution -FileVersionInfo).FileName
Stop-Process -Name TimerResolution -Force
Remove-Item -Path $filePath -Force
}
if ($timerResService) {
$name = (Get-Service -Name 'Set Timer Resolution Service', 'STR' -ErrorAction SilentlyContinue).Name
$serviceExePath = (Get-Process -Name SetTimerResolutionService -FileVersionInfo).FileName
Stop-Service -Name $name -Force
Stop-Process -Name SetTimerResolutionService -Force -ErrorAction SilentlyContinue
sc.exe delete $name *>$null
Remove-Item -Path $serviceExePath -Force
}
if ($islc) {
$filePath = (Get-Process -Name 'Intelligent standby list cleaner ISLC' -FileVersionInfo).FileName
Stop-Process -Name 'Intelligent standby list cleaner ISLC' -Force
Remove-Item -Path $filePath -Force
}
}
#repair svc split threshold
if ($tweak -eq 'Svc Split Threshold') {
Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control' /v 'SvcHostSplitThresholdInKB' /t REG_DWORD /d '3670016' /f *>$null
Reg.exe add 'HKLM\SYSTEM\CurrentControlSet\Control' /v 'SvcHostSplitThresholdInKB' /t REG_DWORD /d '3670016' /f *>$null
}
#repair bcdedit
if ($tweak -eq 'Bcdedit') {
bcdedit.exe /deletevalue useplatformclock *>$null
bcdedit.exe /deletevalue disabledynamictick *>$null
bcdedit.exe /deletevalue useplatformtick *>$null
bcdedit.exe /deletevalue tscsyncpolicy *>$null
}
#repair prefetch
if ($tweak -eq 'Prefetch') {
Reg.exe add 'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters' /v 'EnablePrefetcher' /t REG_DWORD /d '3' /f *>$null
Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control\Session Manager\Memory Management\PrefetchParameters' /v 'EnablePrefetcher' /t REG_DWORD /d '3' /f *>$null
}
#repair win32priorityseperation
if ($tweak -eq 'Win32PrioritySeparation') {
Reg.exe add 'HKLM\SYSTEM\ControlSet001\Control\PriorityControl' /v 'Win32PrioritySeparation' /t REG_DWORD /d '38' /f *>$null
Reg.exe add 'HKLM\SYSTEM\CurrentControlSet\Control\PriorityControl' /v 'Win32PrioritySeparation' /t REG_DWORD /d '38' /f *>$null
}
#repair tcp autotuning
if ($tweak -eq 'Tcp Auto-Tuning') {
netsh.exe interface tcp set global autotuninglevel=normal *>$null
}
#repair spectre meltdown
if ($tweak -eq 'Spectre Meltdown Mitigations') {
Remove-ItemProperty -Path "registry::$currentControlSet\Control\Session Manager\Memory Management" -Name FeatureSettingsOverride -Force -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "registry::$controlSet001\Control\Session Manager\Memory Management" -Name FeatureSettingsOverride -Force -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "registry::$currentControlSet\Control\Session Manager\Memory Management" -Name FeatureSettingsOverrideMask -Force -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "registry::$controlSet001\Control\Session Manager\Memory Management" -Name FeatureSettingsOverrideMask -Force -ErrorAction SilentlyContinue
}
#repair windows error reporting
if ($tweak -eq 'Windows Error Reporting') {
Set-Service -Name WerSvc -StartupType Manual -Force
Remove-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Windows Error Reporting' -Name 'Disabled' -Force -ErrorAction SilentlyContinue
}
#repair csrss priority
if ($tweak -eq 'Csrss Priority') {
Remove-Item -Path 'registry::HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\csrss.exe\PerfOptions' -Recurse -Force
}
}
}
Write-Host 'Checking For Bad Tweaks...'
$getTweaks = checkTweaks
$trueCount = 0
$badTweaksName = @()
foreach ($tweak in $getTweaks.GetEnumerator()) {
#if bad tweak is found
if ($tweak.Value) {
$badTweaksName += $tweak.Key
Write-Host "[$($tweak.Key)]" -ForegroundColor Red
}
else {
$trueCount++
Write-Host "[$($tweak.Key)]" -ForegroundColor Green
}
}
#no bad tweaks found
if ($trueCount -eq $getTweaks.Count) {
Write-Host 'No Bad Tweaks Found!'
$input = Read-Host 'Press ANY Key to Exit...'
if ($input) {
exit
}
}
else {
#use choice cmdlet
choice.exe /c yn /n /m 'Press Y to Repair Bad Tweaks (N to SKIP)'
if ($LASTEXITCODE -eq 1) {
repairTweaks $badTweaksName
#call check tweaks to confirm they have been repaired
$getTweaks = checkTweaks
$trueCount = 0
$badTweaksName = @()
foreach ($tweak in $getTweaks.GetEnumerator()) {
#if bad tweak is found
if ($tweak.Value) {
$badTweaksName += $tweak.Key
}
else {
$trueCount++
}
}
if ($trueCount -eq $getTweaks.Count) {
Write-Host 'Tweaks Repaired Successfully!'
$input = Read-Host 'Press ANY Key to Exit...'
if ($input) {
exit
}
}
else {
Write-Host 'Tweaks Not Repaired:'
foreach ($name in $badTweaksName) {
Write-Host "[$($name)]" -ForegroundColor Red
}
}
}
else {
exit
}
}