Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
LuSlower authored Jul 25, 2024
1 parent 55180ee commit f39871d
Showing 1 changed file with 104 additions and 94 deletions.
198 changes: 104 additions & 94 deletions Ifeo-Utility.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Console {
}
}

# pequeña pero sirve
# Pequeña pero sirve
function Restart-Process {
param (
[string]$processName
Expand All @@ -51,7 +51,9 @@ function Restart-Process {
}
}

# establecer ifeo flags
$ifeoPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\"

# Establecer ifeo flags
function Set-Ifeo {
param (
[string]$process,
Expand All @@ -61,153 +63,188 @@ function Set-Ifeo {
[int]$useLargePages
)

# crear la clave si no existe
$ifeo_key = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\"
$processPath = Join-Path -Path $ifeo_key -ChildPath "$process\PerfOptions"
# Crear la clave si no existe
$processPath = Join-Path -Path $ifeoPath -ChildPath "$process"
$optionsPath = Join-Path -Path $processPath -ChildPath "PerfOptions"

if (-not (Test-Path $processPath)) {
New-Item -Path $processPath -Force | Out-Null
if (-not (Test-Path $optionsPath)) {
New-Item -Path $optionsPath -Force | Out-Null
}

# establecer las global flags
# Establecer las global flags
if ($cpuPriority -ne $null -and $cpuPriority -ne 0) {
Set-ItemProperty -Path $processPath -Name "CpuPriorityClass" -Value $cpuPriority
Set-ItemProperty -Path $optionsPath -Name "CpuPriorityClass" -Value $cpuPriority
} else {
Remove-ItemProperty -Path $processPath -Name "CpuPriorityClass" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path $optionsPath -Name "CpuPriorityClass" -ErrorAction SilentlyContinue
}

if ($ioPriority -ne $null -and $ioPriority -ne 0) {
Set-ItemProperty -Path $processPath -Name "IoPriority" -Value $ioPriority
Set-ItemProperty -Path $optionsPath -Name "IoPriority" -Value $ioPriority
} else {
Remove-ItemProperty -Path $processPath -Name "IoPriority" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path $optionsPath -Name "IoPriority" -ErrorAction SilentlyContinue
}

if ($pagePriority -ne $null -and $PagePriority -ne 0) {
Set-ItemProperty -Path $processPath -Name "PagePriority" -Value $pagePriority
Set-ItemProperty -Path $optionsPath -Name "PagePriority" -Value $pagePriority
} else {
Remove-ItemProperty -Path $processPath -Name "PagePriority" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path $optionsPath -Name "PagePriority" -ErrorAction SilentlyContinue
}

if ($useLargePages -ne $null -and $useLargePages -ne 0) {
Set-ItemProperty -Path $processPath -Name "UseLargePages" -Value $useLargePages
Set-ItemProperty -Path $optionsPath -Name "UseLargePages" -Value $useLargePages
} else {
Remove-ItemProperty -Path $processPath -Name "UseLargePages" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path $optionsPath -Name "UseLargePages" -ErrorAction SilentlyContinue
}

$valueNames = @("CpuPriorityClass", "IoPriority", "PagePriority", "UseLargePages")

# Verificar si la clave esta vacía
$properties = Get-ItemProperty -Path $optionsPath -ErrorAction Stop
$hasValue = $false

foreach ($valueName in $valueNames) {
if ($properties.PSObject.Properties[$valueName]) {
$hasValue = $true
break
}
}

if (-not $hasValue) {
Remove-Item -Path $processPath -Recurse -Force
}

}

function Load-Processes {
$comboBoxProcess.Items.Clear()
Get-Process | ForEach-Object {
$comboBoxProcess.Items.Add($_.Name + ".exe")
$comboBoxProcess.Items.Add($_.Name + ".exe ($($_.Id))")
}
}

function Get-ValueFromText {
param (
[string]$inputText
)

if ($inputText -match '\((\d+)\)') {
return [int]$matches[1]
} elseif ($inputText -match 'delete') {
return $null
} else {
return $null # si no coincide con ningún patrón del match
}
}

# Ocultar consola, crear form
Console -Hide
[System.Windows.Forms.Application]::EnableVisualStyles();
$form = New-Object System.Windows.Forms.Form
$form.Size = New-Object System.Drawing.Size(250, 240)
$form.ClientSize = New-Object System.Drawing.Size(250, 200)
$form.Text = "Ifeo-Utility"
$form.MaximizeBox = $false
$form.MinimizeBox = $false
$form.StartPosition = "CenterScreen"
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle
$form.KeyPreview = $true
$form.Add_KeyDown({
param($sender, $e)
if ($e.KeyCode -eq [System.Windows.Forms.Keys]::F5) {
Load-Processes
}
})

# ComboBox para procesos
# ProcList
$labelProcess = New-Object System.Windows.Forms.Label
$labelProcess.Location = New-Object System.Drawing.Point(10, 15)
$labelProcess.Size = New-Object System.Drawing.Size(70, 13)
$labelProcess.Text = "PROCLIST:"
$labelProcess.Size = New-Object System.Drawing.Size(50, 13)
$labelProcess.Text = "ProcList:"
$form.Controls.Add($labelProcess)

$comboBoxProcess = New-Object System.Windows.Forms.ComboBox
$comboBoxProcess.Location = New-Object System.Drawing.Point(80, 10)
$comboBoxProcess.Size = New-Object System.Drawing.Size(145, 30)
$comboBoxProcess.Location = New-Object System.Drawing.Point(60, 10)
$comboBoxProcess.Size = New-Object System.Drawing.Size(180, 30)
$comboBoxProcess.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$form.Controls.Add($comboBoxProcess)

# ComboBox para CPU Priority Class
# PriorityClass
$labelCpuPriority = New-Object System.Windows.Forms.Label
$labelCpuPriority.Location = New-Object System.Drawing.Point(10, 50)
$labelCpuPriority.Size = New-Object System.Drawing.Size(100, 23)
$labelCpuPriority.Text = "CPU Priority:"
$labelCpuPriority.Location = New-Object System.Drawing.Point(20, 50)
$labelCpuPriority.Size = New-Object System.Drawing.Size(80, 23)
$labelCpuPriority.Text = "PriorityClass:"
$form.Controls.Add($labelCpuPriority)

$comboBoxCpuPriority = New-Object System.Windows.Forms.ComboBox
$comboBoxCpuPriority.Location = New-Object System.Drawing.Point(110, 48)
$comboBoxCpuPriority.Location = New-Object System.Drawing.Point(100, 48)
$comboBoxCpuPriority.Size = New-Object System.Drawing.Size(110, 23)
$comboBoxCpuPriority.Items.AddRange(@("Realtime (4)", "High (3)", "Above Normal (6)", "Normal (2)", "Below Normal (5)", "Low (1)", "default (delete)"))
$comboBoxCpuPriority.Text = "default (delete)"
$comboBoxCpuPriority.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$form.Controls.Add($comboBoxCpuPriority)

# ComboBox para IoPriority
# IoPriority
$labelIoPriority = New-Object System.Windows.Forms.Label
$labelIoPriority.Location = New-Object System.Drawing.Point(10, 80)
$labelIoPriority.Size = New-Object System.Drawing.Size(100, 23)
$labelIoPriority.Text = "IO Priority:"
$labelIoPriority.Location = New-Object System.Drawing.Point(40, 80)
$labelIoPriority.Size = New-Object System.Drawing.Size(60, 23)
$labelIoPriority.Text = "IoPriority:"
$form.Controls.Add($labelIoPriority)

$comboBoxIoPriority = New-Object System.Windows.Forms.ComboBox
$comboBoxIoPriority.Location = New-Object System.Drawing.Point(110, 78)
$comboBoxIoPriority.Location = New-Object System.Drawing.Point(100, 78)
$comboBoxIoPriority.Size = New-Object System.Drawing.Size(110, 23)
$comboBoxIoPriority.Items.AddRange(@("Critical (4)", "High (3)", "Normal (2)", "Low (1)", "default (delete)"))
$comboBoxIoPriority.Text = "default (delete)"
$comboBoxIoPriority.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$form.Controls.Add($comboBoxIoPriority)

# ComboBox para PagePriority
$labelPagePriority = New-Object System.Windows.Forms.Label
$labelPagePriority.Location = New-Object System.Drawing.Point(10, 110)
$labelPagePriority.Size = New-Object System.Drawing.Size(100, 23)
$labelPagePriority.Text = "Page Priority:"
$form.Controls.Add($labelPagePriority)
# MemPriority
$labelMemPriority = New-Object System.Windows.Forms.Label
$labelMemPriority.Location = New-Object System.Drawing.Point(10, 110)
$labelMemPriority.Size = New-Object System.Drawing.Size(85, 23)
$labelMemPriority.Text = "MemoryPriority:"
$form.Controls.Add($labelMemPriority)

$comboBoxPagePriority = New-Object System.Windows.Forms.ComboBox
$comboBoxPagePriority.Location = New-Object System.Drawing.Point(110, 108)
$comboBoxPagePriority.Location = New-Object System.Drawing.Point(100, 108)
$comboBoxPagePriority.Size = New-Object System.Drawing.Size(110, 23)
$comboBoxPagePriority.Items.AddRange(@("Normal (5)", "Below Normal (4)", "Medium (3)", "Low (2)", "VeryLow (1)", "default (delete)"))
$comboBoxPagePriority.Text = "default (delete)"
$comboBoxPagePriority.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$form.Controls.Add($comboBoxPagePriority)

# LargePages
$labelUseLargePages = New-Object System.Windows.Forms.Label
$labelUseLargePages.Location = New-Object System.Drawing.Point(10, 140)
$labelUseLargePages.Size = New-Object System.Drawing.Size(100, 23)
$labelUseLargePages.Text = "Use Large Pages:"
$labelUseLargePages.Location = New-Object System.Drawing.Point(25, 140)
$labelUseLargePages.Size = New-Object System.Drawing.Size(70, 23)
$labelUseLargePages.Text = "LargePages:"
$form.Controls.Add($labelUseLargePages)

$comboBoxUseLargePages = New-Object System.Windows.Forms.ComboBox
$comboBoxUseLargePages.Location = New-Object System.Drawing.Point(110, 138)
$comboBoxUseLargePages.Location = New-Object System.Drawing.Point(100, 138)
$comboBoxUseLargePages.Size = New-Object System.Drawing.Size(110, 23)
$comboBoxUseLargePages.Items.AddRange(@("Enable (1)", "default (delete)"))
$comboBoxUseLargePages.Text = "default (delete)"
$comboBoxUseLargePages.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$form.Controls.Add($comboBoxUseLargePages)

$buttonApply = New-Object System.Windows.Forms.Button
$buttonApply.Size = New-Object System.Drawing.Size(75, 23)
$buttonApply.Location = New-Object System.Drawing.Point(25, 170)
$buttonApply.Text = "Apply"
$form.Controls.Add($buttonApply)

$buttonRefresh = New-Object System.Windows.Forms.Button
$buttonRefresh.Size = New-Object System.Drawing.Size(75, 23)
$buttonRefresh.Location = New-Object System.Drawing.Point(130, 170)
$buttonRefresh.Text = "Refresh"
$buttonRefresh.Add_Click({ Load-Processes })
$form.Controls.Add($buttonRefresh)
# Save
$buttonSave = New-Object System.Windows.Forms.Button
$buttonSave.Size = New-Object System.Drawing.Size(80, 20)
$buttonSave.Location = New-Object System.Drawing.Point(95, 170)
$buttonSave.Text = "Save"
$form.Controls.Add($buttonSave)

# aplicar todos los cambios
$buttonApply.Add_Click({
$ProcessName = $comboBoxProcess.SelectedItem
if ($ProcessName.Count -eq 0) {
$buttonSave.Add_Click({
$process = $comboBoxProcess.SelectedItem
if ($process.Count -eq 0) {
[System.Windows.Forms.MessageBox]::Show("Select a process", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
return
}

$process = $processName.Replace(".exe", "")
$processId = (Get-Process -Name $process).Id
if ($process -match '^(.+?) \(\d+\)$') {
$processName = $matches[1]
}

$cpuPriority = $comboBoxCpuPriority.SelectedItem
$ioPriority = $comboBoxIoPriority.SelectedItem
Expand All @@ -219,39 +256,12 @@ $buttonApply.Add_Click({
return
}

# Convertir a valores númericos
switch ($cpuPriority) {
"Realtime (4)" { $cpuPriorityValue = 4 }
"High (3)" { $cpuPriorityValue = 3 }
"Above Normal (6)" { $cpuPriorityValue = 6 }
"Normal (2)" { $cpuPriorityValue = 2 }
"Below Normal (5)" { $cpuPriorityValue = 5 }
"Low (1)" { $cpuPriorityValue = 1 }
"default (delete)" { $cpuPriorityValue = $null }
}

switch ($ioPriority) {
"Critical (4)" { $ioPriorityValue = 4 }
"High (3)" { $ioPriorityValue = 3 }
"Normal (2)" { $ioPriorityValue = 2 }
"Low (1)" { $ioPriorityValue = 1 }
"default (delete)" { $ioPriorityValue = $null }
}

switch ($pagePriority) {
"Normal (5)" { $pagePriorityValue = 5 }
"Below Normal (4)" { $pagePriorityValue = 4 }
"Medium (3)" { $pagePriorityValue = 3 }
"Low (2)" { $pagePriorityValue = 2 }
"VeryLow (1)" { $pagePriorityValue = 1 }
"default (delete)" { $pagePriorityValue = $null }
}

switch ($useLargePages) {
"Enable (1)" { $useLargePagesValue = 1 }
"default (delete)" { $useLargePagesValue = $null }
}

# Convertir a valores númericos
$cpuPriorityValue = Get-ValueFromText -inputText $cpuPriority
$ioPriorityValue = Get-ValueFromText -inputText $ioPriority
$pagePriorityValue = Get-ValueFromText -inputText $pagePriority
$useLargePagesValue = Get-ValueFromText -inputText $useLargePages

$result = [System.Windows.Forms.MessageBox]::Show("Process: $processName`nPID: $processId`nCPU Priority: $cpuPriority`nIO Priority: $ioPriority`nPage Priority: $pagePriority`nUse Large Pages: $useLargePages`n`nRestart Process?", "Applied settings", [System.Windows.Forms.MessageBoxButtons]::YesNo, [System.Windows.Forms.MessageBoxIcon]::Information)

# aplicar configuracion de ifeo
Expand Down

0 comments on commit f39871d

Please sign in to comment.