function Set-ProcessCpuAffinity {
param(
[ Diagnostics.Process] $Process ,
[ int[ ] ] $Affinity
)
$handle = $Process .Handle
$processAffinityMask = 0
$systemAffinityMask = 0
for ( $i = 0 ; $i -lt $Affinity .Length; $i ++) {
$cpu = $Affinity [ $i ]
$processAffinityMask = $processAffinityMask -bor [ int] ( 1 -shl $cpu )
$systemAffinityMask = $systemAffinityMask -bor [ int] ( 1 -shl $cpu )
}
$success = [ Kernel32] ::SetProcessAffinityMask( $handle , $processAffinityMask )
if ( -not $success ) {
Write-Error "Unable to set process affinity."
}
$success = [ Kernel32] ::SetProcessAffinityMask( $handle , $systemAffinityMask )
if ( -not $success ) {
Write-Error "Unable to set system affinity."
}
}
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class Kernel32 {
[DllImport(" kernel32.dll", SetLastError = true)]
public static extern bool SetProcessAffinityMask(IntPtr handle, IntPtr affinityMask);
}
" @
$logicalProcessors = ( Get-WmiObject Win32_ComputerSystem) .NumberOfLogicalProcessors
$cpuAffinity = 0
$eac = Get-Process -Name "EasyAntiCheat_EOS" -ErrorAction SilentlyContinue
if ( $null -ne $eac ) {
Set-ProcessCpuAffinity -Process $eac -Affinity $cpuAffinity
$priorityClass = [ System.Diagnostics.ProcessPriorityClass] ::Idle
$eac .PriorityClass = $priorityClass
if ( $eac .PriorityClass -eq $priorityClass ) {
Write-Host "Priority class set to $( [ enum] ::GetName( [ System.Diagnostics.ProcessPriorityClass] , $priorityClass) ) "
} else {
Write-Error "Failed to set priority class."
}
} else {
Write-Host "EasyAntiCheat_EOS.exe is not running."
}
$cpuAffinity = 1 .. ( $logicalProcessors - 1 )
$er = Get-Process -Name "eldenring" -ErrorAction SilentlyContinue
if ( $null -ne $er ) {
Set-ProcessCpuAffinity -Process $er -Affinity $cpuAffinity
} else {
Write-Host "eldenring.exe is not running."
}
Write-Host ""
Write-Host "Script execution completed successfully!"
Read-Host -Prompt "Press Enter to quit"