Counter-Strike 2

Counter-Strike 2

View Stats:
Pap En Tik Mar 5, 2024 @ 1:04pm
Set CPU affinity and priority using powershell
Here's a basic powershell script that launches a steam game, waits 5 seconds, then changes CPU affinity and priority of a running process (game) so you won't have to use third-party software or open up task manager every time you wanna play.

Step 1: Copying
Open up Notepad and paste the script below into there:

Start-Process "steam://rungameid/{APP_ID}"

Start-Sleep -Seconds 5

$processName = "YourProcessName"
$process = Get-Process -Name $processName

if ($process -eq $null) {
Write-Host "Process not found: $processName"
} else {
$process.PriorityClass = 'High'
$process.ProcessorAffinity = 0xFE
Write-Host "Completed"
}


Step 2: Editing
In the first line of the script, Replace {APP_ID} with the app ID of your game, for Counter-Strike it's 730 so it should look like Start-Process "steam://rungameid/730". Then replace "YourProcessName" with the actual name of the process (game) that'll be running, for Counter-Strike 2 it's "cs2", make sure to leave the quotation marks in and no need to add .exe at the end of the name. Finally, you'll want to change the affinity, it's calculated in Hexadecimal values and you can calculate your own here: https://bitsum.com/tools/cpu-affinity-calculator/. To change the affinity, find the line $process.ProcessorAffinity = 0xFE and replace "FE" with your own value such as 0x5555.

Step 3: Saving and creating shortcut
Once you're finished editing, click save in notepad and save the file as a .ps1 file to wherever is convenient for you. You won't be able to run the script directly so you'll have to create a shortcut to it which is super simple. Click "create shortcut" on your desktop and paste this into there followed by the path to wherever your .ps1 file is saved: powershell.exe -ExecutionPolicy Bypass -File "Path To .ps1 Script"

The script must be run as administrator, to ensure you're always running as admin, right click on your shortcut and go into properties>advanced and check the "run as administrator" box.

If for some reason you want the script to wait for longer than 5 seconds you can always do that by replacing 5 with the amount of seconds you want it to wait.
Last edited by Pap En Tik; Mar 15, 2024 @ 8:08am
< >
Showing 1-3 of 3 comments
Djo Mar 5, 2024 @ 2:02pm 
Стримлю пока не выйдет операция https://www.youtube.com/live/p_MS5MnuIas?si=PXFTe4ZWKcfYppRO
𐂃𐂃𐂃 Mar 5, 2024 @ 2:27pm 
Nice tutorial, but if you lack good CPU and need to do this, your PC can become unstable because those cpu resources/cores are reserved for important system processes. Don`t forget to put the perfect amount of thermal paste if you set the CPU affinity or priority for a process that is CPU-intensive. Btw the FPS gains from this would be laughable
Pap En Tik Mar 6, 2024 @ 1:45pm 
Originally posted by 𐂃𐂃𐂃:
Nice tutorial, but if you lack good CPU and need to do this, your PC can become unstable because those cpu resources/cores are reserved for important system processes. Don`t forget to put the perfect amount of thermal paste if you set the CPU affinity or priority for a process that is CPU-intensive. Btw the FPS gains from this would be laughable
I just uncheck core 0 because I get an extra 10-20 fps and latency mon tests show that it's the core with the highest latency so you may even get some latency gains, presumably because that's the core that Windows schedules tasks to. And it only changes the amount of cores for the game specifically so system processes aren't affected by this tweak. PCs with loads of cores (16 or more) will, depending on the game, benefit from disabling hyperthreading as well, sadly I don't have that problem as I only have 8 cores.
< >
Showing 1-3 of 3 comments
Per page: 1530 50

Date Posted: Mar 5, 2024 @ 1:04pm
Posts: 3