Jump to content

Setting Cpu Affinity


 Share

Recommended Posts

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.

Link to comment
Share on other sites

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:

Link to comment
Share on other sites

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:

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...