WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Process UDFs

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Set Current Process Affinity

 Keywords:  SetProcessorsAll Set Current Process Affinity GetCurrentProcess GetProcessAffinityMask SetProcessAffinityMask

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Set current process affinity to all processors.
; return - @True on success, otherwise, @False
#DefineFunction SetProcessorsAll()
   bReturn   = @FALSE
   hKernel   = DllLoad(DirWindows(1):"Kernel32.dll")
   hProcMask = BinaryAlloc(4)
   hSysMask  = BinaryAlloc(4)

   hCurrent = DllCall(hKernel, long:"GetCurrentProcess")     ; Usually -1
   While @TRUE
      If !DllCall(hKernel, long:"GetProcessAffinityMask", long:hCurrent, lpbinary:hProcMask, lpbinary:hSysMask) Then Break
      BinaryEodSet(hSysMask, 4)
      dwSysMask = BinaryPeek4(hSysMask, 0)
      bReturn   = DllCall(hKernel, long:"SetProcessAffinityMask", long:hCurrent, long:dwSysMask)
      Break
   EndWhile

   DllFree(hKernel)
   BinaryFree(hSysMask)
   BinaryFree(hProcMask)

   Return bReturn
#EndFunction


; Test
bResult = SetProcessorsAll()
Message("Affinite Set", bResult)

Article ID:   W18384
Filename:   Set Current Process Affinity.txt
File Created: 2010:02:01:10:14:46
Last Updated: 2010:02:01:10:14:46