Processor Affinity - Add Set Affinity to Context Menu

Page 1 of 3 123 LastLast
    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
    Designer Media Ltd


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


       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
    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
    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
    Processor Affinity - Add Set Affinity to Context Menu-default.jpgProcessor Affinity - Add Set Affinity to Context Menu-added_exe_shortcuts.jpg
    Processor Affinity - Add Set Affinity to Context Menu-added_pinned_to_start_menu.jpgProcessor Affinity - Add Set Affinity to Context Menu-added_takbar_icons.jpg



    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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







  1. Posts : 6
    Windows 7 Ultimate x64
       #1

    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 Computer


  2. Posts : 70,219
    64-bit Windows 10 Pro
    Thread Starter
       #2

    Hello Atoteh,

    Sure, you could add the contents of each .bat file into just one .bat file instead if you like. :)
      My Computer


  3. Posts : 6
    Windows 7 Ultimate x64
       #3

    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 :)
    Last edited by AtotehZ; 20 Mar 2013 at 06:17. Reason: Update
      My Computer


  4. Posts : 10
    Win NeXT 7 SP 1 x64 bit Pro
       #4

    hmm what about making casscade context menu with this content ?, could smone explain me why my context menu dont reveal when i get mose on exe and move over entry ive created by code below
    Code:
    Windows Registry Editor Version 5.00
    [HKEY_CLASSES_ROOT\exefile\shell\rdzenie]
    @=""
    "SubCommands"="cpu0123;cpu123;cpu23;cpu2;cpu3"
    "Icon"="%windir%\\System32\\SetupApi.Dll,21"
    "MUIVerb"="Koligacja procesorów"
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\cpu0123]
    @="CPU - 0,1,2,3"
    "icon"="%windir%\\System32\\NetCenter.Dll,12"
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\cpu0123\command]
    @="cmd.exe /c start \"rdzenie\" /affinity f \"%1\""
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\cpu123]
    @="CPU - 1,2,3"
    "icon"="%windir%\\System32\\NetCenter.Dll,11"
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\cpu123\command]
    @="cmd.exe /c start \"rdzenie\" /affinity e \"%1\""
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\cpu23]
    @="CPU - 2,3"
    "icon"="%windir%\\System32\\NetCenter.Dll,10"
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\cpu23\command]
    @="cmd.exe /c start \"rdzenie\" /affinity c \"%1\""
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\cpu3]
    @="CPU - 3"
    "icon"="%windir%\\System32\\NetCenter.Dll,8"
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\cpu3\command]
    @="cmd.exe /c start \"rdzenie\" /affinity 8 \"%1\""
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\cpu2]
    @="CPU - 2"
    "icon"="%windir%\\System32\\NetCenter.Dll,8"
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\cpu2\command]
    @="cmd.exe /c start \"rdzenie\" /affinity 4 \"%1\""
    @ belowed files works, but only on exe files, what to add to make it possible on liks to exe files ( content menu shows on lnk to exe but nothing happens ;P)

    Code:
    Windows Registry Editor Version 5.00
    [HKEY_CLASSES_ROOT\exefile\shell\rdzenie]
    @=""
    "SubCommands"=""
    "Icon"="%windir%\\System32\\SetupApi.Dll,21"
    "MUIVerb"="Koligacja procesorów"
    [HKEY_CLASSES_ROOT\exefile\shell\rdzenie\Shell]
    [HKEY_CLASSES_ROOT\exefile\shell\rdzenie\Shell\cpu0123]
    "muiverb"="CPU - 0,1,2,3"
    "icon"="%windir%\\System32\\NetCenter.Dll,12"
    [HKEY_CLASSES_ROOT\exefile\shell\rdzenie\Shell\cpu0123\command]
    @="start "Koligacja CPU - 1,2,3" /affinity E %1 & pause"
    Last edited by kkmks; 04 Oct 2016 at 10:25.
      My Computer


  5. Posts : 70,219
    64-bit Windows 10 Pro
    Thread Starter
       #5

    Hello kkmks, :)

    This should work for you instead. You just had the command incorrect a bit.

    Code:
    Windows Registry Editor Version 5.00
     
    [HKEY_CLASSES_ROOT\exefile\shell\rdzenie]
    @=""
    "SubCommands"=""
    "Icon"="%windir%\\System32\\SetupApi.Dll,21"
    "MUIVerb"="Koligacja procesorów"
     
    [HKEY_CLASSES_ROOT\exefile\shell\rdzenie\Shell\cpu0123]
    "muiverb"="CPU - 0,1,2,3"
    "icon"="%windir%\\System32\\NetCenter.Dll,12"
     
    [HKEY_CLASSES_ROOT\exefile\shell\rdzenie\Shell\cpu0123\command]
    @="cmd /c start \"Koligacja CPU - 1,2,3\" /affinity E \"%1\""
      My Computer


  6. Posts : 10
    Win NeXT 7 SP 1 x64 bit Pro
       #6

    yeah it works on exe files, but it won work on shortcuts ;'(thats wahts makes me all the problem here ;P
    who run program directly from original exe ;P
    what is strange that your original non cascade files works fine even with lnk
      My Computer


  7. Posts : 70,219
    64-bit Windows 10 Pro
    Thread Starter
       #7

    What I posted worked on a shortcut of notepad.exe for me.

    As a test, create a new shortcut of notepad.exe to see if it works for you as well.
      My Computer


  8. Posts : 10
    Win NeXT 7 SP 1 x64 bit Pro
       #8

    nope win 7 x 64 dont respond ;P but thx 4 trying
      My Computer


  9. Posts : 70,219
    64-bit Windows 10 Pro
    Thread Starter
       #9

    Ok. Let's strip it back down to a non cascading context menu to see how it works for you with this below.

    Code:
    Windows Registry Editor Version 5.00
     
    [-HKEY_CLASSES_ROOT\exefile\shell\rdzenie]
     
    [HKEY_CLASSES_ROOT\exefile\shell\rdzenie]
    @="Koligacja procesorów"
    "Icon"="%windir%\\System32\\SetupApi.Dll,21"
     
    [HKEY_CLASSES_ROOT\exefile\shell\rdzenie\command]
    @="cmd.exe /c start \"Run with CPU-0 Affinity\" /affinity E \"%1\""
      My Computer


 
Page 1 of 3 123 LastLast

  Related Discussions
Our Sites
Site Links
About 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 21:27.
Find Us