-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSet-ProcessPriorityIFEO.ps1
More file actions
132 lines (110 loc) · 4.94 KB
/
Set-ProcessPriorityIFEO.ps1
File metadata and controls
132 lines (110 loc) · 4.94 KB
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
<#
.SYNOPSIS
Manipulate the Process Priority with IFEO (registry)
IFEO is mentioned in Windows Internals book
#https://answers.microsoft.com/en-us/windows/forum/windows_10-performance/how-to-permanently-set-priority-processes-using/df82bd40-ce52-4b84-af34-4d93da17d079
.DESCRIPTION
Manipulate the Process Priority with IFEO (registry)
Image File Execution Options are registry settings that are permanent and take effect immediately, as long as they are not changed or deleted manually.
These settings remain in effect even if the system is restarted.
.PARAMETER processName
Name of process with .exe - in the following format: processname.exe
.PARAMETER priorityname
What Priority you want to manipulate?
.PARAMETER IOpriorityValue
Special Value-Parameter used for IOpriority
.PARAMETER CpuPriorityClassValue
Special Value-Parameter used for CpuPriorityClass
.PARAMETER PagePriorityValue
Special Value-Parameter used for PagePriority
.PARAMETER WorkingSetLimitInKBValueHEXDecimal
Special HEXDecimal-Value-Parameter (for example 0x2A) used for WorkingSetLimitInKB
.PARAMETER WorkingSetLimitInKBValueDecimal
Special Decimal-Value-Parameter used for WorkingSetLimitInKB
.EXAMPLE
Set-ProcessPriorityIFEO -processName "mrt.exe" -priorityname "CpuPriorityClass" -CpuPriorityClassValue High
.EXAMPLE
Set-ProcessPriorityIFEO -processName "notepad.exe" -priorityname WorkingSetLimitInKB -WorkingSetLimitInKBValueDecimal 1328
.EXAMPLE
Set-ProcessPriorityIFEO -processName "notepad.exe" -priorityname WorkingSetLimitInKB -WorkingSetLimitInKBValueDecimal 41
.NOTES
Image File Execution Options are registry settings that are permanent and take effect immediately, as long as they are not changed or deleted manually.
These settings remain in effect even if the system is restarted.
Test, test and test before you use it in production!
Thorsten Enderlein, 2023
Twitter: @endi24
github: https://github.com/endoleg/
#>
function Set-ProcessPriorityIFEO {
param (
[Parameter(Mandatory=$true)]
[string]$processName,
[Parameter(Mandatory=$true)]
[ValidateSet("CpuPriorityClass", "PagePriority", "IOPriority", "WorkingSetLimitInKB")]
[string]$priorityname,
[ValidateSet("VeryLow", "Low", "Normal", "High", "Critical")]
[string]$IOpriorityValue,
[ValidateSet("Idle", "Normal", "High", "Realtime", "BelowNormal", "AboveNormal")]
[string]$CpuPriorityClassValue,
[ValidateSet("Idle", "VeryLow", "Low", "Background3", "Background4", "Normal")]
[string]$PagePriorityValue,
[string]$WorkingSetLimitInKBValueHEXDecimal,
[string]$WorkingSetLimitInKBValueDecimal
)
switch ($IOpriorityValue) {
"VeryLow" {$value = 0}
"Low" {$value = 1}
"Normal" {$value = 2}
"High" {$value = 3}
"Critical" {$value = 4}
}
switch ($CpuPriorityClassValue) {
"Idle" {$value = 1}
"Normal" {$value = 2}
"High" {$value = 3}
"Realtime" {$value = 4}
"BelowNormal" {$value = 5}
"AboveNormal" {$value = 6}
}
switch ($PagePriorityValue) {
"Idle" {$value = 0}
"VeryLow" {$value = 1}
"Low" {$value = 2}
"Background3" {$value = 3}
"Background4" {$value = 4}
"Normal" {$value = 5}
}
$registryKey = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\$processName\PerfOptions"
if (!(Test-Path -Path $registryKey)) {
New-Item -Path $registryKey -Force | Out-Null
}
switch ($priorityname) {
"CpuPriorityClass" {
New-ItemProperty -LiteralPath $registryKey -Name $priorityname -Value $value -PropertyType DWord -Force
}
"PagePriority" {
New-ItemProperty -LiteralPath $registryKey -Name $priorityname -Value $value -PropertyType DWord -Force
}
"IOPriority" {
New-ItemProperty -LiteralPath $registryKey -Name $priorityname -Value $value -PropertyType DWord -Force
}
"WorkingSetLimitInKB" {
if ($WorkingSetLimitInKBValueHEXDecimal) {
New-ItemProperty -LiteralPath $registryKey -Name $priorityname -Value $WorkingSetLimitInKBValueHEXDecimal -PropertyType DWord -Force # 0x2A
} elseif ($WorkingSetLimitInKBValueDecimal) {
New-ItemProperty -LiteralPath $registryKey -Name $priorityname -Value $WorkingSetLimitInKBValueDecimal -PropertyType DWord -Force # 42
}
}
}
}
<# for Remote-action
#Aufbau einer Remotesession auf einen einzugebenden Computer
$computerName = Read-Host "Computername, auf dem SetProcessPriorityIFEO ausgeführt werden soll"
$session = New-PSSession -ComputerName $computerName
#Ausfuehren eines Sciprtblocks auf dem Computer - hier: SetProcessPriorityIFEO aus ca. Zeile 123
Invoke-Command -Session $session -ScriptBlock {
#Block
}
#Disconnect-PSSession -Session $session
Remove-PSSession -Session $session
#>