Solved changing affinity of running process with native windows ...

Hidde663 / My first build
July 25, 2018 at 07:49:33
Specs: Windows 10 Pro 64bit, i5-6600K[delid]@4.8GHz/4.3GHz@1.4v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-30 1T 2700MHz@1.37v
I'm trying to make a script that can offload all running processes to 1 cpu core therefore allowing for example core 2 to have a solid 0% load untill told otherwise

So for example:

::1= imagename 4=session id (has to be 1)
for /f "tokens=1,4" in %a ('tasklist') do if %b equ 1 start affinityscript.bat %a "%coreCODE%"

%coreCODE% will be defined this way{

set/a ans=0x%core1%*0x1+0x%core2%*0x2+0x%core3%*0x4+0x%core4%*0x8
if '%ans%'=='10' set ans=A
if '%ans%'=='11' set ans=B
if '%ans%'=='12' set ans=C
if '%ans%'=='13' set ans=D
if '%ans%'=='14' set ans=E
if '%ans%'=='15' set ans=F
::0000
::1+4 = 1001 = 9 = 0xA = A
::core 1(0) = 1
::core 2(1) = 2
::core 3(2) = 4
::core 4(3) = 8
::sum values to use more cores
::0xf = 1111 – a mask allowing use of only the first four processors:

}

any ideas?

I'm willing to program it in powershell\wmic\vbscript\javascript, or anything else i can run natively on windows 10, but batch would be nice :)

i5-6600K[delid]@4.8GHz/4.3GHz@1.4v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-30 1T 2700MHz@1.37v
MSI Armor RX 570 4GB@1395Mhz core@1.168v/1920MHz BiosModded


See More: changing affinity of running process with native windows ...

Reply ↓  Report •

#1
July 25, 2018 at 13:35:24
✔ Best Answer
Not sure why you want to cripple your performance like that, but whatever. Here's your PowerShell. Run it elevated to modify more of your system, but not every process will let you change its affinity.
ps | % { $_.ProcessorAffinity = 1 }

How To Ask Questions The Smart Way


Reply ↓  Report •

#2
July 26, 2018 at 01:08:28
I'm not too good at power-shell, but i ended up with:

@echo off&setlocal enabledelayedexpansion
for /f "tokens=1,4" %%a in ('tasklist') do (
if '%%b'=='1' (
set "var=%%a"
PowerShell "$Process = Get-Process !var:.exe=!; $Process.ProcessorAffinity=1"
)
)

and it works, jeej

i5-6600K[delid]@4.8GHz/4.3GHz@1.4v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-30 1T 2700MHz@1.37v
MSI Armor RX 570 4GB@1395Mhz core@1.168v/1920MHz BiosModded


Reply ↓  Report •

#3
July 26, 2018 at 10:47:21
You really need to get away from batch. It was never good as a scripting language, and it's being depreciated as fast as Microsoft can manage. I'd recommend PowerShell (v3 or up) as it's the non-depreciated choice. You could also adopt something like C# if compiling code isn't too much of a hindrance.

How To Ask Questions The Smart Way


Reply ↓  Report •

Related Solutions

#4
July 26, 2018 at 15:39:23
yeah i should have switched to powershell years ago, maby its time

i5-6600K[delid]@4.8GHz/4.3GHz@1.4v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-30 1T 2700MHz@1.37v
MSI Armor RX 570 4GB@1395Mhz core@1.168v/1920MHz BiosModded


Reply ↓  Report •

#5
July 27, 2018 at 07:30:08
Well, if you're going to pick it up, start in the ISE. It has its own version of Intelesense. That'll help to get you up to speed.

How To Ask Questions The Smart Way


Reply ↓  Report •

Ask Question