In standard scripting, there is no method of changing the affinity of a running process. That means that both batch and VBScript are out as options. There is however, a method provided by a .Net class that will allow you to change the affinity of a running process; and luckily for us, it's exposed to PowerShell, the next generation scripting technology available in both Windows Vista and Windows 7. To begin, you need to grab the current running process' instance using the Get-Process cmdlet.
Code:
$game = Get-Process -name race07
Here, race07 is the name of the game's process as you see it listed in Task Manager.
Once you have an object reference for the process, you can change its processor affinity using the ProcessorAffinity property of the System.Diagnostics.Process (the class object that was returned by the Get-Process cmdlet) .Net class. If you don't know what all of that means, that's ok. You can ignore the over speak and look at the example below.
Code:
$game.ProcessorAffinity = 0x0001
In the above example, we change the property to have a value of 0x0001. The hex value of 1 represents the first processor. Incidentally, the hex value 0x0002 represents the second processor. So to switch it to the second processor, you add this line:
Code:
$game.ProcessorAffinity = 0x0002
Here's where it gets slightly confusing. To switch the affinity to
both processors, you will use the hex value 0x0003.
Code:
$game.ProcessorAffinity = 0x0003
While it looks like the two values are added together, it's actually a bitmask value that is the result of a bitwise conjunction. (0x0001 AND 0x0002 = 0x0003) Here again, bitwise calculations are far beyond the scope of this post. Just trust me that that's what's really going on behind the scenes.
Phew! Ok, so let's turn this jumbled mess into a script already! Open up notepad or some other simple text editor and add the following lines.
Code:
$game = Get-Process -name race07
$game.ProcessorAffinity = 0x0001
$game.ProcessorAffinity = 0x0002
$game.ProcessorAffinity = 0x0003
Now save your text file with a .PS1 extension (the default extension for Windows PowerShell scripts) and you're all set. Once your game is running, just double click your script file to run it and it should go through the motions you described.
Sorry it's not a batch script, but it gets the job done!