How to Set Process CPU Affinity Permanently in Windows
In this article
You cannot set permanent CPU affinity or process priority directly through the standard Task Manager interface because these settings are volatile and reset when the application closes. To achieve persistence, you must use a combination of the built-in Start-Process PowerShell command and Windows Task Scheduler to launch the program with specific processor flags automatically.
What You'll Need
- A Windows PC running Windows 10 or Windows 11 (Home or Pro editions).
- Administrator privileges on your account.
- The full file path to the executable (.exe) of the application you want to configure.
- Familiarity with basic PowerShell syntax.
Step-by-Step
- Identify the Executable Path: Locate the shortcut or installation folder of the application you wish to optimize. Right-click the executable file, select Properties, and copy the full directory path from the "Location" field, appending the filename. For example:
C:\Program Files\Game\game.exe. Note this path down. - Determine Desired Affinity: Decide which CPU cores the application should use. In hexadecimal format, Core 0 is 1, Core 1 is 2, Core 2 is 4, Core 3 is 8, etc. If you want to restrict a game to only Cores 0 and 1, the value is 3 (1+2). If you want it to run on all cores, you can skip affinity setting or use the maximum bitmask for your system.
- Create a PowerShell Script: Open Notepad and create a new text file. Paste the following command structure, replacing the path and affinity mask with your specific values:
Save this file as$process = Start-Process -FilePath "C:\Path\To\Your\App.exe" -PassThru $process.PriorityClass = "High" Start-Sleep -Seconds 2 $process.ProcessorAffinity = 0x3 # Hex for Cores 0 and 1RunApp.ps1in a secure location likeC:\Scripts. - Configure Execution Policy: Because PowerShell blocks script execution by default, you need to allow local scripts. Open PowerShell as Administrator and run:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser. TypeYto confirm. - Create a Scheduled Task: Press
Win + R, typetaskschd.msc, and hit Enter. Click "Create Task" in the right-hand panel. - General Tab: Name the task clearly (e.g., "Launch Game with Fixed Affinity"). Check the box for "Run whether user is logged on or not" and "Run with highest privileges." Select the correct user account if prompted.
- Triggers Tab: Click "New" to define when this runs. You can set it to start at log-on, or at a specific time. For most users, starting at log-on ensures the app is ready when needed.
- Actions Tab: Click "New." Set the action to "Start a program." In the "Program/script" field, enter:
powershell.exe. In the "Add arguments" field, enter:-ExecutionPolicy Bypass -File "C:\Scripts\RunApp.ps1". Ensure the path matches your saved script. - Conditions and Settings Tabs: Under Conditions, uncheck "Start the task only if the computer is on AC power" if you are on a laptop. Under Settings, check "Allow task to be run on demand" and "If the task fails, restart every" to ensure reliability.
- Test the Configuration: Log out and back in, or manually trigger the task from the scheduler. Open Task Manager, find the application, right-click it, go to Details, and verify that the "Affinity" column matches your hex setting and the Priority is set to High.
Common Mistakes
Using Decimal Instead of Hexadecimal: The most frequent error is entering decimal core numbers into the affinity mask. Windows expects hexadecimal values. Using decimal 3 might result in unexpected behavior. Always use the 0x prefix or convert correctly (Core 0=1, Core 1=2, Core 2=4, Core 3=8).
Incorrect File Paths: Spaces in file paths will break the PowerShell command if not enclosed in quotes. Ensure your script uses double quotes around the file path argument.
Ignoring Execution Policies: Even if you create the task, PowerShell may block the script from running silently in the background if the execution policy is strict. Always verify the policy allows local scripts.
Tips
Use High Priority Carefully: Setting a process to "Realtime" priority can freeze your entire system if the application hangs. Stick to "High" priority for games and applications. "High" gives the app preference over background tasks without starving the OS kernel.
Limit Affinity for Background Apps: While gamers often limit affinity to save threads for the main CPU core, modern multi-core processors benefit from balanced distribution. Only restrict affinity if you have a specific issue with thread stealing or stuttering.
Monitor Performance: Use Resource Monitor (resmon) to see if your affinity changes actually reduce context switching. If the CPU usage is already low, changing affinity may provide no perceptible benefit.
Troubleshooting
Task Fails to Launch: If the scheduled task does nothing, check the "Last Run Result" in Task Scheduler. Error code 0x1 indicates access denied; ensure you ran the task creation with Administrator rights. Error 0x2 means the file was not found; double-check the path in the script.
Affinity Resets After Update: Some applications update their own configuration files or replace executables, which may break the script reference. If an update occurs, re-verify the executable path and adjust the script if necessary.
PowerShell Window Appears: If you see a black console window flash when the app starts, modify the PowerShell command in the Task Scheduler to hide the window. Change the arguments to include -WindowStyle Hidden.
Frequently Asked Questions
Can I do this without writing a script?
No. Windows does not offer a native UI checkbox for permanent affinity. You must automate the launch process using PowerShell and Task Scheduler to inject the parameters at startup.
Will this work on Windows 11?
Yes. The Task Scheduler and PowerShell commands are identical across Windows 10 and Windows 11. The interface for creating tasks looks slightly different but functions the same way.
Does this improve FPS?
It depends. On older CPUs with many cores, limiting affinity can prevent the game from scheduling threads on slower efficiency cores. On modern CPUs, it usually has minimal impact unless you are experiencing specific stuttering issues related to thread migration.
Is it safe to set Realtime priority?
It is generally unsafe. Realtime priority overrides the operating system's ability to manage resources. If the application freezes, your mouse and keyboard may become unresponsive until you force quit the process via Task Manager.
Can I set this for multiple apps at once?
You can create multiple scheduled tasks, one for each application. Alternatively, you can expand the PowerShell script to launch multiple processes sequentially, though separate tasks are easier to manage and debug.