Start an app with Affinity batch file (.bat)

Any problems with your Installation or other install related questions, please post here

Moderators: Steve Waite, SysAdmin

Start an app with Affinity batch file (.bat)

Postby Steve Waite » Wed Jan 27, 2016 7:41 am

We can start apps with an Affinity Mask with the Windows batch system. We first right-click in expolorer where we want to create a new batch file and choose New Text File. This makes a new file with .txt extension.

Here is an example of a command line in a .bat file to launch Notepad on Logical processors 0 and 3 in binary set digits zero and three = 1001 the binary value is equivalent to 9 hexadecimal:


Code: Select all
C:\Windows\System32\cmd.exe /c start "Notepad" /affinity 9 "C:\Windows\notepad.exe"

and with higher numbers:

A00=2560=10,10,00,00,00,00 LPs 9 and 11

Code: Select all
C:\Windows\System32\cmd.exe /c start "Notepad" /affinity A00 "C:\Windows\notepad.exe"

(remember to use HEX values for /affinity)

The commands can be typed into the "Target" line of a desktop Shortcut (lnk) as a single line.

Investigating other methods that may prove more reliable depending on the system security and other features:

I will use a fictitious weather program called FSWeather.exe found in the folder "C:\Program Files (x86)\FSWeather".

Rename it FSWeather.bat
Choose Edit and type in the command lines:

Code: Select all
CD /D "C:\Program Files (x86)\FSWeather"
C:\Windows\System32\cmd.exe /C start /affinity A0 FSWeather.exe

A0 Hex=(10,10,00,00)=7,5

With HT enabled on a 4 core CPU we have 8 Logical Processors. We can use an affinity mask in the FS JOBSCHEDULER section AffinityMask=85=(01,01,01,01)=6,4,2,0 of the .cfg file.

We can make a shortcut to the bat file to place on the desktop or wherever, or we can simply double-click the batch file.

On a 4 core HT enabled system, we get good performance starting our weather engine away from core zero and use all four cores for simulator.

Note: We change directory in the .bat, because the start processor cannot resolve "C:\Program Files (x86)\FSWeather\FSWeather.exe" when there are spaces in the path. Make sure the exe name does not have spaces too.

Another way to do each exe on a single line, where we can use spaces and quotes:
Code: Select all
start /B "" /affinity A0 "C:\Program Files (x86)\FSWeather\FSWeather.exe"
start /B "" /affinity A0 "C:\Program Files (x86)\FSTraffic\FSTraffic.exe"

10,10,00,00 = A0 Hex 7,5 - addons
01,01,01,01 = 85 Decimal 6,4,2,0 - sim
software architect at
equipment: i9-9980Xe 64GB 2xRTX2080ti NVLink 2TB M.2,
i9-9900X 64GB RTX2080ti 2TB M.2, i7-3960X 32GB GTX680 4TB RAID10,
Steve Waite
Posts: 4718
Joined: Wed Jun 29, 2011 12:02 am

Return to Installation

Who is online

Users browsing this forum: No registered users and 3 guests