What's new

CPU Affinity Shortcut for a Program - Create in Windows

How to Create a Shortcut to Run an Application with a Set CPU Affinity in Windows


Processor affinity or CPU Pinning enables the binding and un-binding of a process or thread to a physical CPU or a range of CPUs, so that the process or thread in question will run only on the CPU or range of CPUs in question, rather than being able to run on any CPU

By default, Windows runs an application on all available cores of the processor. If you have a multi-core processor, then this tutorial will show you how to set the processor affinity of an application to control which core(s) of the processor the application will run on.

If the application and CPU supports Symmetric Multiprocessing (SMP) or HyperThreading (HT), then Windows will automatically adjust the application's usage of each processor core for the best performance. You will not gain much, if anything, from manually changing the processor affinity for these type of applications.

If you have more then one processor intensive applications running, then you could improve their performance by setting the processor affinity of their processes to run on a different core(s). This way they are not competing for the resources of the same core(s).


This tutorial will show you how to create a shortcut that will always run an application with a set CPU affinity by default in XP, Vista, Windows 7, and Windows 8.



Here's How:

1. This step will show you how many CPU cores you have, and how to figure the hex value to use at step 3 below for the CPU(s) you want to run the application on.

NOTE: If you should need any assistance with this step, then please feel free to post. I'll be happy to help.


A) Open Task Manager (CTRL+Shift+ESC) in more details view, click/tap on the Processes (XP, Vista, Windows 7) OR Details (Windows 8) tab, right click or press and hold on any process in the Name column, and click/tap on Set affinity. (see screenshot below)

NOTE: This will show you how many CPU cores you have. I have 12 CPU cores numbered from 0 to 11.

Task_Manager_Affinity-all.png


B) For how many CPU cores you have will also be how long the binary number will be. Since I have 12 CPU cores, the binary number will be 12 zeros 000000000000. Each zero in the binary number represents a CPU core number from right to left. In my case with 12 CPU cores, the far right 0 in the binary number will be for CPU 0, and the far left 0 will be for CPU 11. (see screenshot below)

C) For each CPU number you want to run the application on, replace 0 (off) with 1 (on) in the binary number for the CPU numbers.

For example, if I wanted to run the application only on CPU 0, then my binary number would be changed to 000000000001. To run the application on CPU 0 and CPU 3, I would use 000000001001. (see screenshot below)

binary.jpg


D) Go the website below, and type your binary number from step 1C above into the Binary field. This will convert the binary number to a hexadecimal (hex) that you will need to use at step 3 below.

Website: Binary/Decimal/Hexadecimal Converter


For example, with my 000000000001 binary number, I get a hex value of 1. (see screenshot below)

Binary-Decimal-Hexadecimal-Converter.png


2. Right click or press and hold on an empty area of your desktop, and click/tap on New and Shortcut.

3. Type the command below into the location area, and click/tap on the Next button. (see screenshot below)


cmd.exe /c start "Program Name" /affinity # "Full path of application file"


For example: I would type this command below exactly if I wanted to create a shortcut to run Process Monitor on only CPU 0 (step 1), and it's .exe file is located at "E:\Programs\Process Monitor 3.05\Procmon.exe".

(For only on CPU 0)
cmd.exe /c start "Process Monitor" /affinity 1 "E:\Programs\Process Monitor 3.05\Procmon.exe"

(For on CPU 0 and CPU 3)
cmd.exe /c start "Process Monitor" /affinity 9 "E:\Programs\Process Monitor 3.05\Procmon.exe"


Note   Note
Substitute Program Name in the command with the actual program's name within quotes.

Substitute # in the command for the affinity # with the hex value (ex: 1) from step 1D above.

Substitute Full path of application file in the command with the full path of the file within quotes.



shortcut-1.jpg

4. Type any name you would like to give the shortcut, and click/tap on the Finish button. (see screenshot below)

shortcut-2.jpg

5. Right click or press and hold on the new shortcut, and click/tap on Properties.

6. Click/tap on the Shortcut tab, then click/tap on the Change Icon button. (see screenshot below)

Shortcut-3.png

7. In the line under "Look for icons in this file", copy and paste the same full path of the application file used in the shortcut below, and press Enter. (see screenshot below)

For example: E:\Programs\Process Monitor 3.05\Procmon.exe


Shortcut-4.jpg

8. Select (highlight) the icon you want for the shortcut, and click/tap on OK. (see screenshot above)
NOTE: You can use any icon that you would like instead though.

9. Click/tap on OK. (see screenshot below step 6)

10. In Vista and Windows 7, you can now Pin to Taskbar (Windows 7 only) or Pin to Start Menu, add to Quick Launch, assign a keyboard shortcut to it, or move this shortcut to where you like for easy use.

11. In Windows 8, you can Pin to Taskbar on desktop, Pin to Start screen, add to Quick Launch, assign a keyboard shortcut to it, or move this shortcut to where you like for easy use.



That's it,
Shawn


 

Attachments

  • CPU.jpg
    CPU.jpg
    3 KB · Views: 15
Last edited by a moderator:

wykydtronik

New Member
Has anyone got this working with OBS Studio 64 bit? I got mine to work, I wanted to contribute to this thread.

This forum is frustrating... I can't post to this thread without Cloudflare blocking it! I get

"Oops! We ran into some problems.
Oops! We ran into some problems. Please try again later. More error details may be in the browser console."

It's blocking he command that OP is talking about. Below is a screenshot of how I got OBS running with this command.

notes-affinity-obs.PNG
 
Last edited:

My Computer

System One

  • OS
    Windows 10 Pro
    Computer type
    PC/Desktop
    CPU
    i9 9900k
    Motherboard
    ASUS Strix
    Memory
    16GB DDR4
    Graphics Card(s)
    MSI 1080 Ti
    Browser
    Chrome
    Antivirus
    Netscape Navigator

z3r010

BOFH
Administrator
This forum is frustrating... I can't post to this thread without Cloudflare blocking it! I get

"Oops! We ran into some problems.
Oops! We ran into some problems. Please try again later. More error details may be in the browser console."
I 've never seen it do that before, are you trying to attach something?
 

My Computer

System One

  • OS
    Windows 10
    Name
    John Fairbrother
    Show second system?
    No
    Computer type
    PC/Desktop
    System Manufacturer/Model
    me
    CPU
    i9
    Occupation
    Forum Admin
    Country Flag
    England

wykydtronik

New Member
I 've never seen it do that before, are you trying to attach something?

No, I think it has to do with the lines where quotes and .exe is. In the screenshot the second line seems to trigger the Cloudflare error.

One thing to note: I changed my hexadecimal to F to utilize 4 CPU's. OBS didn't like being limited to 2.
 

My Computer

System One

  • OS
    Windows 10 Pro
    Computer type
    PC/Desktop
    CPU
    i9 9900k
    Motherboard
    ASUS Strix
    Memory
    16GB DDR4
    Graphics Card(s)
    MSI 1080 Ti
    Browser
    Chrome
    Antivirus
    Netscape Navigator

SweetPapaya

New Member
Hi Brink,
Excellent post and valuable information. However, I currently have AMD Ryzen 3700x CPU 8 cores, but in task manager I see 16 cores, see snip below. Could you please let me know which of them I have to choose in order to allocate my last core (8)? Do I have to take into consideration 2 cores (I assume one of them is virtual core?). Or do I just allocate one of them? I am running a game which is designed to run on just one core therefore I wanted to allocate my last core which is used the least by my PC and would not interfere with other processes. I tried to allocate myself and noticed that the 14th is the 8th core but then I am left with the 15th core as per task manager. So what do I do with this - should I allocate it together with the 14th core assuming that 2x cores per task manager = 1 real core?

1575930650041.png
1575930666157.png


Your input would be much appreciated.
 

My Computer

System One

  • OS
    Windows 10
    Computer type
    PC/Desktop
    CPU
    AMD Ryzen
    Motherboard
    x570
    Memory
    32gb
    Graphics Card(s)
    5700 xt
    Browser
    Chrome

Brink

Administrator
Administrator
mvp
Hello @SweetPapaya, and welcome to Eight Forums. :)

AMD has multithreading like Intel's Hyper Threading.

It doubles your physical 8 cores to effectively be 16 (0 to 15) instead.

You could use core 15 for the last one.
 

My Computer

System One

  • OS
    64-bit Windows 10
    Name
    Shawn Brink
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Custom self built
    CPU
    Intel i7-8700K OC'd to 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    16 GB (8GBx2) G.SKILL TridentZ DDR4 3200 MHz
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    3 x 27" Asus VE278Q
    Screen Resolution
    1920x1080
    Hard Drives
    1TB Samsung 970 EVO Plus M.2,
    250GB Samsung 960 EVO M.2,
    6TB WD Black WD6001FZWX
    8TB WD MyCloudEX2Ultra NAS
    PSU
    OCZ Series Gold OCZZ1000M 1000W
    Case
    Thermaltake Core P3
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master
    Internet Speed
    1 Gb/s Download and 35 Mb/s Upload
    Browser
    Internet Explorer 11
    Antivirus
    Malwarebyte Anti-Malware Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    Linksys EA9500 router,
    Arris SB8200 cable modem,
    APC SMART-UPS RT 1000 XL - SURT1000XLI,
    Lumia 1520 phone
    State/Region Flag
    us oklahoma

SweetPapaya

New Member
Hello @SweetPapaya, and welcome to Eight Forums. :)

AMD has multithreading like Intel's Hyper Threading.

It doubles your physical 8 cores to effectively be 16 (0 to 15) instead.

You could use core 15 for the last one.

Thank you, Brink :)

What about core 14 then? Do they not work in a pair?
 

My Computer

System One

  • OS
    Windows 10
    Computer type
    PC/Desktop
    CPU
    AMD Ryzen
    Motherboard
    x570
    Memory
    32gb
    Graphics Card(s)
    5700 xt
    Browser
    Chrome

Brink

Administrator
Administrator
mvp
Thank you, Brink :)

What about core 14 then? Do they not work in a pair?


They will behave as single cores, but you could select more than one if wanted.
 

My Computer

System One

  • OS
    64-bit Windows 10
    Name
    Shawn Brink
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Custom self built
    CPU
    Intel i7-8700K OC'd to 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    16 GB (8GBx2) G.SKILL TridentZ DDR4 3200 MHz
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    3 x 27" Asus VE278Q
    Screen Resolution
    1920x1080
    Hard Drives
    1TB Samsung 970 EVO Plus M.2,
    250GB Samsung 960 EVO M.2,
    6TB WD Black WD6001FZWX
    8TB WD MyCloudEX2Ultra NAS
    PSU
    OCZ Series Gold OCZZ1000M 1000W
    Case
    Thermaltake Core P3
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master
    Internet Speed
    1 Gb/s Download and 35 Mb/s Upload
    Browser
    Internet Explorer 11
    Antivirus
    Malwarebyte Anti-Malware Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    Linksys EA9500 router,
    Arris SB8200 cable modem,
    APC SMART-UPS RT 1000 XL - SURT1000XLI,
    Lumia 1520 phone
    State/Region Flag
    us oklahoma

Fuzzee

New Member
Hi, i am having a few custom Programs that i use with Microsoft Access Runtime 32bit in Windows 10 64 bit and i want them to only use CPU 0.
Some reports in my programs give me in random cases the error message "System Resource Exceeded" and the only solution that works is if manually set the affinity to CPU 0. I am confused on how to make the shortcut to set the affinity from the start at CPU0.
Ms Access is installed in location below:
C:\Program Files (x86)\Microsoft Office\OFFICE11\MSACCESS.EXE
And my Programs are in C:\Apps\.. For example:
C:\Apps\Orders.mde or C:\Apps\Support.mde

i tried the following but with no success!!
C:\Windows\System32\cmd.exe /c start "MSACCESS.EXE" /affinity 1 "C:\Apps\Orders.mde"
C:\Windows\System32\cmd.exe /c start "Orders.mde" /affinity 1 "C:\Apps\Orders.mde"
C:\Windows\System32\cmd.exe /c start "C:\Program Files (x86)\Microsoft Office\OFFICE11" /affinity 1 "C:\Apps\Orders.mde"
C:\Windows\System32\cmd.exe /c start "OFFICE11" /affinity 1 "C:\Apps\Orders.mde"
C:\Windows\System32\cmd.exe /c start "Microsoft Office Access" /affinity 1 "C:\Apps\Orders.mde"
C:\Windows\System32\cmd.exe /c start "Microsoft Office Access (32 bit)" /affinity 1 "C:\Apps\Orders.mde"

Any ideas?
 

My Computer

System One

  • OS
    Win10
    Computer type
    PC/Desktop

Brink

Administrator
Administrator
mvp
Hi, i am having a few custom Programs that i use with Microsoft Access Runtime 32bit in Windows 10 64 bit and i want them to only use CPU 0.
Some reports in my programs give me in random cases the error message "System Resource Exceeded" and the only solution that works is if manually set the affinity to CPU 0. I am confused on how to make the shortcut to set the affinity from the start at CPU0.
Ms Access is installed in location below:
C:\Program Files (x86)\Microsoft Office\OFFICE11\MSACCESS.EXE
And my Programs are in C:\Apps\.. For example:
C:\Apps\Orders.mde or C:\Apps\Support.mde

i tried the following but with no success!!
C:\Windows\System32\cmd.exe /c start "MSACCESS.EXE" /affinity 1 "C:\Apps\Orders.mde"
C:\Windows\System32\cmd.exe /c start "Orders.mde" /affinity 1 "C:\Apps\Orders.mde"
C:\Windows\System32\cmd.exe /c start "C:\Program Files (x86)\Microsoft Office\OFFICE11" /affinity 1 "C:\Apps\Orders.mde"
C:\Windows\System32\cmd.exe /c start "OFFICE11" /affinity 1 "C:\Apps\Orders.mde"
C:\Windows\System32\cmd.exe /c start "Microsoft Office Access" /affinity 1 "C:\Apps\Orders.mde"
C:\Windows\System32\cmd.exe /c start "Microsoft Office Access (32 bit)" /affinity 1 "C:\Apps\Orders.mde"

Any ideas?

Hello Fuzzee, and welcome to Eight Forums. :)

You should be able to use this below for the shortcut.

You would have wanted to use the full path of the executable file in the part in red below.

cmd.exe /c start "Microsoft Access" /affinity 1 "C:\Program Files (x86)\Microsoft Office\OFFICE11\MSACCESS.EXE" "C:\Apps\Orders.mde"
 

My Computer

System One

  • OS
    64-bit Windows 10
    Name
    Shawn Brink
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Custom self built
    CPU
    Intel i7-8700K OC'd to 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    16 GB (8GBx2) G.SKILL TridentZ DDR4 3200 MHz
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    3 x 27" Asus VE278Q
    Screen Resolution
    1920x1080
    Hard Drives
    1TB Samsung 970 EVO Plus M.2,
    250GB Samsung 960 EVO M.2,
    6TB WD Black WD6001FZWX
    8TB WD MyCloudEX2Ultra NAS
    PSU
    OCZ Series Gold OCZZ1000M 1000W
    Case
    Thermaltake Core P3
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master
    Internet Speed
    1 Gb/s Download and 35 Mb/s Upload
    Browser
    Internet Explorer 11
    Antivirus
    Malwarebyte Anti-Malware Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    Linksys EA9500 router,
    Arris SB8200 cable modem,
    APC SMART-UPS RT 1000 XL - SURT1000XLI,
    Lumia 1520 phone
    State/Region Flag
    us oklahoma

Fuzzee

New Member
Hello Fuzzee, and welcome to Eight Forums. :)

You should be able to use this below for the shortcut.

You would have wanted to use the full path of the executable file in the part in red below.

cmd.exe /c start "Microsoft Access" /affinity 1 "C:\Program Files (x86)\Microsoft Office\OFFICE11\MSACCESS.EXE" "C:\Apps\Orders.mde"


Thanks Brink it works fine!
 

My Computer

System One

  • OS
    Win10
    Computer type
    PC/Desktop

Brink

Administrator
Administrator
mvp

My Computer

System One

  • OS
    64-bit Windows 10
    Name
    Shawn Brink
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Custom self built
    CPU
    Intel i7-8700K OC'd to 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    16 GB (8GBx2) G.SKILL TridentZ DDR4 3200 MHz
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    3 x 27" Asus VE278Q
    Screen Resolution
    1920x1080
    Hard Drives
    1TB Samsung 970 EVO Plus M.2,
    250GB Samsung 960 EVO M.2,
    6TB WD Black WD6001FZWX
    8TB WD MyCloudEX2Ultra NAS
    PSU
    OCZ Series Gold OCZZ1000M 1000W
    Case
    Thermaltake Core P3
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master
    Internet Speed
    1 Gb/s Download and 35 Mb/s Upload
    Browser
    Internet Explorer 11
    Antivirus
    Malwarebyte Anti-Malware Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    Linksys EA9500 router,
    Arris SB8200 cable modem,
    APC SMART-UPS RT 1000 XL - SURT1000XLI,
    Lumia 1520 phone
    State/Region Flag
    us oklahoma

Dracoflame

New Member
Many thanks to OP, this worked great for setting cores on my 3900x, 12c/24T sitting at 10-30% usage under load and running neither program effectively at all.
I was trying to stream on twitch and I was getting stuttering, lag and dropped frames in game and in OBS.
For apex legends I set the affinity in the launcher app-Orgine. Which let all programs it started run with inherited settings, especially helpful since apex didn't allow for easy setting of affinity because of the anti cheat blocked the change.

Using: C:\Windows\System32\cmd.exe /c start "Orgin.exe" /affinity FFF "C:\Program Files (x86)\Origin\Origin.exe"
This set the game to just use the first and fastest CCD0 leaving the slightly slower CCD1 for OBS

Setting up OBS I was greeted with "failed to find locale/en-US.ini" same as wykydtronik above

Using:C:\Windows\System32\cmd.exe /c start "OBS Studio (64bit).Ink" /affinity FFF000 "C:\Program Files\obs-studio\bin\64bit\obs64.exe"


I fixed it by just opening up the shortcut and changing where it started in from C:\Windows\system32 to "C:\Program Files\obs-studio\bin\64bit"
Hopes this helps someone!

The 3900x is a beast I basically dedicated a 3600x to each program. I'm able to run apex legends at 1080p 144hz buttery smooth and run OBS medium 1080p at 6000Kbs with no lag or dropped frames
 

My Computer

System One

  • OS
    Windows 10
    Computer type
    PC/Desktop
    CPU
    3900x
    Motherboard
    Gigabyte Aorus Elite X570 wifi
    Memory
    32gb 3600mhz
    Graphics Card(s)
    msi 1070 TI
    Browser
    firefox
    Antivirus
    windows defender

Brink

Administrator
Administrator
mvp
I'm glad it could help @Dracoflame, and welcome to Eight Forums. :)
 

My Computer

System One

  • OS
    64-bit Windows 10
    Name
    Shawn Brink
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Custom self built
    CPU
    Intel i7-8700K OC'd to 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    16 GB (8GBx2) G.SKILL TridentZ DDR4 3200 MHz
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    3 x 27" Asus VE278Q
    Screen Resolution
    1920x1080
    Hard Drives
    1TB Samsung 970 EVO Plus M.2,
    250GB Samsung 960 EVO M.2,
    6TB WD Black WD6001FZWX
    8TB WD MyCloudEX2Ultra NAS
    PSU
    OCZ Series Gold OCZZ1000M 1000W
    Case
    Thermaltake Core P3
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master
    Internet Speed
    1 Gb/s Download and 35 Mb/s Upload
    Browser
    Internet Explorer 11
    Antivirus
    Malwarebyte Anti-Malware Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    Linksys EA9500 router,
    Arris SB8200 cable modem,
    APC SMART-UPS RT 1000 XL - SURT1000XLI,
    Lumia 1520 phone
    State/Region Flag
    us oklahoma

EndofForever

New Member
I found this thread with the exact problem that @wykydtronik and @Dracoflame had with OBS lagging and dropping frames and using the shortcut method of automatically assigning affinity on OBS startup to make sure OBS stayed ahead of encoding. Imagine my relief when I found other people with exact same problem on this thread. @Dracoflame even has the same CPU as me!

I fixed it by just opening up the shortcut and changing where it started in from C:\Windows\system32 to "C:\Program Files\obs-studio\bin\64bit"​

Hopes this helps someone!
This solution gave me a headache because I didn't understand what exactly changing "C:\Windows\system32 to "C:\Program Files\obs-studio\bin\64bit"" meant.
So what I did is I navigated to c:/Windows/systm32 in my file browser and literally copy/pasted the cmd.exe executable file and plopped it directly in the same folder as my obs64.exe ("C:\Program Files\obs-studio\bin\64bit"). After this, the exact line I put in the shortcut was:

C:\Program Files\obs-studio\bin\64bit\cmd.exe /c start "OBS Studio" /affinity FFF000 "C:\Program Files\obs-studio\bin\64bit\obs64.exe"​


I hope this clears up this problem for anyone else in the future!
 

My Computer

System One

  • OS
    Windows 10
    Computer type
    PC/Desktop
    System Manufacturer/Model
    White box
    CPU
    R9 3900x
    Motherboard
    Asus Prime x570-P
    Memory
    64GB DDR4 3200MHz Corsair Vengence
    Graphics Card(s)
    Radeon RX 5700XT
    Browser
    Microsoft Edge
    Antivirus
    WIndows Defender

Users Who Are Viewing This Thread (Users: 0, Guests: 2)

Top