第一个参数是进程PID,第二个参数是CPU ID( 从1起,而不是从0起)ProcessSetAffinity(1464,2)
Func ProcessSetAffinity($iProcessID,$iProcessor = 1)
Local $i_PID = ProcessExists($iProcessID)
If Not $i_PID Then
SetError(1)
Return -1
EndIf
Local $hDLL = DllOpen('kernel32.dll')
Local $aProcessHandle = DllCall($hDLL, 'int', 'OpenProcess', 'int', 0x0200, 'int', False, 'int', $i_PID)
if $aProcessHandle[0] = 0 Then
SetError(2)
Return -1
EndIf
Local $aAffinity = DllCall($hDLL, 'int', 'SetProcessAffinityMask', 'int', $aProcessHandle[0], 'int', $iProcessor)
DllCall($hDLL, 'int', 'CloseHandle', 'int', $aProcessHandle[0])
DllClose($hDLL)
Return $aAffinity[0]
EndFunc ;==>ProcessSetAffinity
|