Jump to content
Sign in to follow this  
gauss5546

Setting Cpu Affinity

Recommended Posts

gauss5546

I have looked through the Auto It help guide and forums quite a few times but I have a question that I cannot find an answer to.

Is it possible to set a program to have an affinity for one core with Auto It?

Visually the way to do this is to open the task manager, click the processes tab, right click on the process, click set affinity, check off which cpu(s) you want it to use.

I am looking for a quick way through Auto It that I can change the affinity for a certain process.

Share this post


Link to post
Share on other sites
rasim

I have looked through the Auto It help guide and forums quite a few times but I have a question that I cannot find an answer to.

Is it possible to set a program to have an affinity for one core with Auto It?

Visually the way to do this is to open the task manager, click the processes tab, right click on the process, click set affinity, check off which cpu(s) you want it to use.

I am looking for a quick way through Auto It that I can change the affinity for a certain process.

Example:

#include <WinAPI.au3>

Global Const $PROCESS_ALL_ACCESS = 0x1F0FFF

$sPID = Run("notepad.exe")

$hProc = _WinAPI_OpenProcess($PROCESS_ALL_ACCESS, False, $sPID)
$aRet = _WinAPI_GetProcessAffinityMask($hProc)

MsgBox(0, "", $aRet[0] & @LF & _
              $aRet[1] & @LF & _
              $aRet[2] & @LF)

;_WinAPI_SetProcessAffinityMask($hProc, 0x01) ;Set affinity for 1-st core
;_WinAPI_SetProcessAffinityMask($hProc, 0x02) ;Set affinity for 2-nd core
_WinAPI_SetProcessAffinityMask($hProc, 0x03) ;Set affinity for both cores

_WinAPI_CloseHandle($hProc)

:mellow:

Share this post


Link to post
Share on other sites
gauss5546

Thanks! I had to edit that script a bit to get it to work correctly and this is what I got it to.

CODE
#include <WinAPI.au3>

$sPID = Run("notepad.exe")

$hProc = _WinAPI_OpenProcess($PROCESS_ALL_ACCESS, False, $sPID)

$aRet = _WinAPI_GetProcessAffinityMask($hProc)

;_WinAPI_SetProcessAffinityMask($hProc, 0x01) ;Set affinity for 1-st core

;_WinAPI_SetProcessAffinityMask($hProc, 0x02) ;Set affinity for 2-nd core

_WinAPI_SetProcessAffinityMask($hProc, 0x03) ;Set affinity for both cores

_WinAPI_CloseHandle($hProc)

It works great now! :mellow:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.