Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Processor Affinity - Add Set Affinity to Context Menu



Processor Affinity - Add Set Affinity to Context Menu

How to Add or Remove "Run with CPU Affinity" to the Context Menu
Published by Brink
10 May 2010
Default Processor Affinity - Add Set Affinity to Context Menu

How to Add or Remove "Run with CPU Affinity" to the Context Menu


information   Information
By default, Vista, Windows 7, and Windows 8 runs an application on all available cores of the processor. If you have a multi-core processor, then this will show you how to add or remove Run with CPU Affinity from all application files and shortcuts context menu to set processor affinity to an application to control which core(s) of the processor an 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.
Note   Note
The affinity changes you make to the current instance of an application or process are only temporary and not set permanently.

Once you close the application or restart your system, Windows forgets your set affinity and automatically sets back the default affinity of the application running on all available cores of the processor.
warning   Warning
I have included REG downloads below to add context menu items for up to a 12 core processor. How many cores you actually have will depend on your processor. You can add one or more of any of the following Run with CPU Affinity context menu items below to use as needed.

DO NOT ADD A CONTEXT MENU ITEM numbered above how many cores you actually have.

You can quickly see how many processor cores you have by opening Task Manager (CTRL+SHIFT+ESC), clicking on the Performance tab, and counting how many CPU Usage History graphs you have.

Processor Affinity - Add Set Affinity to Context Menu-task_manager.jpg

EXAMPLE: Run with CPU Affinity Added or Removed from Context Menu
Name:  Default.jpg
Views: 3515
Size:  34.5 KBName:  Added_exe_shortcuts.jpg
Views: 3520
Size:  48.3 KB
Processor Affinity - Add Set Affinity to Context Menu-added_pinned_to_start_menu.jpgName:  Added_Takbar_icons.jpg
Views: 3533
Size:  83.6 KB



OPTION ONE
Using a REG File Download

NOTE: You can only merge these REG files while logged in as an administrator. See warning box above.

CPU-0 = Processor Core 1, CPU-1 = Processor Core 2, etc.......
1. To Add Run with CPU-0 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-0_Affinity_to_Context_Menu.reg
download
2. To Remove Run with CPU-0 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-0_Affinity_from_Context_Menu.reg
download
3. To Add Run with CPU-1 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-1_Affinity_to_Context_Menu.reg
download
4. To Remove Run with CPU-1 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-1_Affinity_from_Context_Menu.reg
download
5. To Add Run with CPU-2 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-2_Affinity_to_Context_Menu.reg
download
6. To Remove Run with CPU-2 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-2_Affinity_from_Context_Menu.reg
download
7. To Add Run with CPU-3 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-3_Affinity_to_Context_Menu.reg
download
8. To Remove Run with CPU-3 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-3_Affinity_from_Context_Menu.reg
download
9. To Add Run with CPU-4 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-4_Affinity_to_Context_Menu.reg
download
10. To Remove Run with CPU-4 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-4_Affinity_from_Context_Menu.reg
download
11. To Add Run with CPU-5 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-5_Affinity_to_Context_Menu.reg
download
12. To Remove Run with CPU-5 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-5_Affinity_from_Context_Menu.reg
download
13. To Add Run with CPU-6 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-6_Affinity_to_Context_Menu.reg
download
14. To Remove Run with CPU-6 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-6_Affinity_from_Context_Menu.reg
download
15. To Add Run with CPU-7 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-7_Affinity_to_Context_Menu.reg
download
16. To Remove Run with CPU-7 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-7_Affinity_from_Context_Menu.reg
download
17. To Add Run with CPU-8 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-8_Affinity_to_Context_Menu.reg
download
18. To Remove Run with CPU-8 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-8_Affinity_from_Context_Menu.reg
download
19. To Add Run with CPU-9 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-9_Affinity_to_Context_Menu.reg
download
20. To Remove Run with CPU-9 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-9_Affinity_from_Context_Menu.reg
download
21. To Add Run with CPU-10 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-10_Affinity_to_Context_Menu.reg
download
22. To Remove Run with CPU-10 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-0_Affinity_from_Context_Menu.reg
download
23. To Add Run with CPU-11 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-11_Affinity_to_Context_Menu.reg
download
24. To Remove Run with CPU-11 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-11_Affinity_from_Context_Menu.reg
download
25. Save the .reg file to your desktop.

26. Double click/tap on the downloaded .reg file to merge it.

27. Clic/tap on Run, Yes (UAC), Yes, and OK when prompted.

28. When finished, you can delete the downloaded .reg file(s) on the desktop if you like.



OPTION TWO
Using a BAT File Download

NOTE: You can only merge these BAT files while logged in as an administrator. See warning box above. Special thanks to Dwarf for this option.

CPU-0 = Processor Core 1, CPU-1 = Processor Core 2, etc.......
1. To Add Run with CPU-0 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-0_Affinity_to_Context_Menu.bat
download
2. To Remove Run with CPU-0 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-0_Affinity_from_Context_Menu.bat
download
3. To Add Run with CPU-1 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-1_Affinity_to_Context_Menu.bat
download
4. To Remove Run with CPU-1 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-1_Affinity_from_Context_Menu.bat
download
5. To Add Run with CPU-2 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-2_Affinity_to_Context_Menu.bat
download
6. To Remove Run with CPU-2 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-2_Affinity_from_Context_Menu.bat
download
7. To Add Run with CPU-3 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-3_Affinity_to_Context_Menu.bat
download
8. To Remove Run with CPU-3 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-3_Affinity_from_Context_Menu.bat
download
9. To Add Run with CPU-4 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-4_Affinity_to_Context_Menu.bat
download
10. To Remove Run with CPU-4 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-4_Affinity_from_Context_Menu.bat
download
11. To Add Run with CPU-5 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-5_Affinity_to_Context_Menu.bat
download
12. To Remove Run with CPU-5 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-5_Affinity_from_Context_Menu.bat
download
13. To Add Run with CPU-6 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-6_Affinity_to_Context_Menu.bat
download
14. To Remove Run with CPU-6 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-6_Affinity_from_Context_Menu.bat
download
15. To Add Run with CPU-7 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-7_Affinity_to_Context_Menu.bat
download
16. To Remove Run with CPU-7 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-7_Affinity_from_Context_Menu.bat
download
17. To Add Run with CPU-8 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-8_Affinity_to_Context_Menu.bat
download
18. To Remove Run with CPU-8 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-8_Affinity_from_Context_Menu.bat
download
19. To Add Run with CPU-9 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-9_Affinity_to_Context_Menu.bat
download
20. To Remove Run with CPU-9 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-9_Affinity_from_Context_Menu.bat
download
21. To Add Run with CPU-10 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-10_Affinity_to_Context_Menu.bat
download
22. To Remove Run with CPU-10 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-0_Affinity_from_Context_Menu.bat
download
23. To Add Run with CPU-11 Affinity to Context Menu
A) Click on the Download button below to download the file below.

Add_Run_with_CPU-11_Affinity_to_Context_Menu.bat
download
24. To Remove Run with CPU-11 Affinity from Context Menu
A) Click on the Download button below to download the
file below.

Remove_Run_with_CPU-11_Affinity_from_Context_Menu.bat
download
25. Save the .bat file to your desktop.

26. Right click or press and hold on the downloaded .bat file, and click on Run as administrator.

27. Click/tap on Run and Yes (UAC) when prompted.

28. When finished, you can delete the downloaded .bat file(s) on the desktop if you like.
That's it,
Shawn




Published by
20 Mar 2013   #1
AtotehZ

Windows 7 Ultimate x64
 
 

Hello,

This is just what I need. I have to set cpu affinity for my program every time I launch it.

How can I add the batch scripts to each other? From 0-11 I need only want 4-11 to run the program. Otherwise it hangs.

Do I just open them in an editor and add them to each other in one batch?


My System SpecsSystem Spec
20 Mar 2013   #2
Brink
Microsoft MVP

64-bit Windows 8.1 Enterprise
 
 

Hello Atoteh,

Sure, you could add the contents of each .bat file into just one .bat file instead if you like.
My System SpecsSystem Spec
20 Mar 2013   #3
AtotehZ

Windows 7 Ultimate x64
 
 

So this:
Code:
@ECHO OFF
REG ADD "HKCR\exefile\shell\Run with CPU-4 Affinity" /ve /f
REG ADD "HKCR\exefile\shell\Run with CPU-4 Affinity\Command" /ve /t REG_SZ /d "cmd.exe /c start \"Run with CPU-4 Affinity\" /affinity 5 \"%%1\"" /f
REG ADD "HKCR\exefile\shell\Run with CPU-5 Affinity" /ve /f
REG ADD "HKCR\exefile\shell\Run with CPU-5 Affinity\Command" /ve /t REG_SZ /d "cmd.exe /c start \"Run with CPU-5 Affinity\" /affinity 6 \"%%1\"" /f
REG ADD "HKCR\exefile\shell\Run with CPU-6 Affinity" /ve /f
REG ADD "HKCR\exefile\shell\Run with CPU-6 Affinity\Command" /ve /t REG_SZ /d "cmd.exe /c start \"Run with CPU-6 Affinity\" /affinity 7 \"%%1\"" /f
REG ADD "HKCR\exefile\shell\Run with CPU-7 Affinity" /ve /f
REG ADD "HKCR\exefile\shell\Run with CPU-7 Affinity\Command" /ve /t REG_SZ /d "cmd.exe /c start \"Run with CPU-7 Affinity\" /affinity 8 \"%%1\"" /f
REG ADD "HKCR\exefile\shell\Run with CPU-8 Affinity" /ve /f
REG ADD "HKCR\exefile\shell\Run with CPU-8 Affinity\Command" /ve /t REG_SZ /d "cmd.exe /c start \"Run with CPU-8 Affinity\" /affinity 9 \"%%1\"" /f
REG ADD "HKCR\exefile\shell\Run with CPU-9 Affinity" /ve /f
REG ADD "HKCR\exefile\shell\Run with CPU-9 Affinity\Command" /ve /t REG_SZ /d "cmd.exe /c start \"Run with CPU-9 Affinity\" /affinity 10 \"%%1\"" /f
REG ADD "HKCR\exefile\shell\Run with CPU-10 Affinity" /ve /f
REG ADD "HKCR\exefile\shell\Run with CPU-10 Affinity\Command" /ve /t REG_SZ /d "cmd.exe /c start \"Run with CPU-10 Affinity\" /affinity 11 \"%%1\"" /f
REG ADD "HKCR\exefile\shell\Run with CPU-11 Affinity" /ve /f
REG ADD "HKCR\exefile\shell\Run with CPU-11 Affinity\Command" /ve /t REG_SZ /d "cmd.exe /c start \"Run with CPU-11 Affinity\" /affinity 12 \"%%1\"" /f
..would result in my CPU affinity being set to CPU- 0 to 3 off and CPU- 4 to 11 on?

Can this be done for a specific *.exe only? I mean, can I still let other processes run on CPU- 0 to 3? Is there a way to clean it up a bit? Maybe 2 strings that sets the affinity of all instead of 16, 2 for each processor core.

I know how to add to the registry at the same time as I launch the program, but I don't know how to make the removal batch run automatically when I close the program. How is that done?

***UPDATE***
I found a solution that fits my problem better. I will let the rest of my question stay though, maybe others can get use of that.

This command line sets the CPU affinity for the program as you start it:
C:\Windows\System32\cmd.exe /C start "" /affinity XX "*PATH OF PROGRAM*"

XX = The hexadecimal number for the logical processors you want to use.

1 = use CPU 0
2 = use CPU 1
3 = use CPU 1 and 0
4 = use CPU 2 ...
9 = use CPU 3 and 0
A = use CPU 3 and 1 ...
F = use CPU 3, 2, 1 and 0

If you have a lot of CPUs to choose from you might wanna use binary numbers and convert it to hexadecimal afterwards.

1 = use CPU 0
10 = use CPU 1
100 = use CPU 2
...
100000000000 = use CPU 11
110 = use 1 and 2
101010101010 = use CPU 11, 9, 7, 5, 3 and 1

The placement of a certain digit represents a certain processor. The value of that digit represents if the processor is to be on or off.

You can convert it here:
http://www.mathsisfun.com/binary-dec...converter.html

Hope I helped a little in return for your time
My System SpecsSystem Spec
.


Comment

 Processor Affinity - Add Set Affinity to Context Menu




Tutorial Tools



Similar help and support threads for2: Processor Affinity - Add Set Affinity to Context Menu
Windows 7 Tutorial Category
How to access "Processor Affinity" screen without Task Manager? General Discussion
Save process priority and affinity Performance & Maintenance
Mouse lag and fps problems related to processor affinity Hardware & Devices
All games crash unless I set affinity - 2 cores Gaming
How to set affinity for Media Center? Media Center
Processor Affinity - Set for Applications Tutorials
Set affinity in task mgr as default Performance & Maintenance

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 07:02 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33