Affinity Command in CMD


  1. Posts : 3
    Windows XP, Windows 7, Windows 8.1, Windows 10, Linux Mint 17.3, OS X 10.9
       #1

    Affinity Command in CMD


    In past Windows OS's , I was always able to change the CPU affinity with a simple line in a .bat file.

    Code:
    start /affinity # program.exe
    # depends on which CPUs you want to run the program with.

    Now, in Windows 10, this command does not work. I've tried with the -affinity # parameter, but without any luck. Yes, I am running both the .exe and the .bat file in Administrator mode, and yes I have full ownership of the folder both files are in.
    Has the code changed somehow in Windows 10?

    And before you answer, please don't refer to the solution of using the Task Manager to change affinity. I want a permanent solution, not a temporary one.

    Thanks,
    - Eetheart
      My Computer


  2. Posts : 234
    Windows 10 Pro (x64)
       #2

    How are you implementing the command? Affinity takes a hexadecimal number.
    For exmaple:
    processor 0: 0x1
    processor 1: 0x2
    processor 2: 0x4
    processor 2 & 4: 0x14

    You can use the calculator to get these numbers. In Programmer mode, go to the bit toggling keypad.

    Affinity Command in CMD-calculator.png

    And before you state it. Yes this is how it worked in Windows 7 as well. Using plain decimal numbers (1-8 etc.) did not correspond to a CPU number. You just never double checked the command in task manager to make sure it set that process to the CPU you picked. I.E. using "affinity 3" did not restrict the process to processor 3. No, instead it restricted the process to CPU 0 and 1.
      My Computer


  3. Posts : 3
    Windows XP, Windows 7, Windows 8.1, Windows 10, Linux Mint 17.3, OS X 10.9
    Thread Starter
       #3

    logicearth said:
    How are you implementing the command? Affinity takes a hexadecimal number.

    And before you state it. Yes this is how it worked in Windows 7 as well. Using plain decimal numbers (1-8 etc.) did not correspond to a CPU number. You just never double checked the command in task manager to make sure it set that process to the CPU you picked. I.E. using "affinity 3" did not restrict the process to processor 3. No, instead it restricted the process to CPU 0 and 1.
    Yes, I am perfectly aware of how the hexadecimal system works with Affinity. In my case I'm trying to make said program only run on CPU 0, thus the bat file looks like this:

    Code:
    Start /affinity 1 program.exe
    But Windows seems to ignore it, running the program with all cores. And it's not just that specific program, I've tested with multiple and it's all the same. It works just fine with the exact same command, exact same program on my Windows 8.1 PC, but not on my Windows 10.

    Maybe someone with Windows 10 can test and confirm to see if I'm the only one with this problem.
      My Computer


  4. Posts : 234
    Windows 10 Pro (x64)
       #4

    Works just fine "start /affinity 1 notepad.exe" is locked to CPU 0. Checked in Task Manager. And ever other variation I try.

    Even tested on a Surface Pro 4, worked as expected.
      My Computer


  5. Posts : 3
    Windows XP, Windows 7, Windows 8.1, Windows 10, Linux Mint 17.3, OS X 10.9
    Thread Starter
       #5

    logicearth said:
    Works just fine "start /affinity 1 notepad.exe" is locked to CPU 0. Checked in Task Manager. And ever other variation I try.

    Even tested on a Surface Pro 4, worked as expected.
    Thanks for testing it out. I'm baffled as to why it won't do that on mine. I'm gonna give this one a few more days as I've got another laptop arriving this week with Windows 10, so I'm going to test it on that one and see how it behaves.

    UPDATE: After a restart, I tested it again and it worked. Don't ask me how or why, but I'm pleased! It seems like the good ol' restart trick still works wonders.
      My Computer


  6. Posts : 1
    Windows 10
       #6

    But how to I lock the affinity to all cores But core 0?


    logicearth said:
    Works just fine "start /affinity 1 notepad.exe" is locked to CPU 0. Checked in Task Manager. And ever other variation I try.

    Even tested on a Surface Pro 4, worked as expected.
    I am writing a script to open a program that just does not like core 0 so I need to know how to use this to set the affinity to all cores but core 0. Any insight?
      My Computer


  7. Posts : 3,272
    Win10
       #7

    Try the following:

    Go to one of the Affinity Calculators such as:
    FSX Times - FIP Gauge Store
    or
    Affinity Mask Calculator - Prepar3D (P3D V1, V2, V3 & V4) - Flight Simulator X - FSX Steam Edition

    Input the cores you want selected.

    The calculator will give you the binary value; input that into one of the binary to hex converters such as:
    https://coolconversion.com/math/bina..._11111_in_hex_

    Use the hex value in your command and hope it works!
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 20:13.
Find Us




Windows 10 Forums