How to access "Processor Affinity" screen without Task Manager?

GbeTech

New member
Local time
5:42 PM
Messages
15
How to access "Processor Affinity" screen without Task Manager?

Hey.

I'm trying to create a macro, through Auto HotKey, that will automatically set the processor affinity of some program.

It's problematic because the only way I know of, is to right click the process in Task Manager. The process's location changes each time, so I can't direct the macro to it. (I'm directing it by providing pixel coordinates, XY)

Is there a file, or static window - the processes window in Task Manager isn't static, it's constantly updating - that can give me access to the processor affinity window?


Thanks.
 

My Computer

OS
Win7 Pro SP1 64
CPU
Intel i7 860
Motherboard
Gigabyte GA-P55M-UD2 P55
Memory
Transcend 2GB DDR3 133
Graphics Card(s)
ATI Radeon 5770
Sound Card
M-Audio Profire 610

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
HP
OS
Microsoft Windows 7 Ultimate 64-bit 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i5-2400S CPU @ 2.50GHz
Motherboard
PEGATRON CORPORATION 2AC2
Memory
6.00 GB
Graphics Card(s)
Intel(R) HD Graphics
Sound Card
(1) Realtek High Definition Audio (2) HD Pro Webcam C910
Monitor(s) Displays
MAIN: HP S2331; Second: HP 2009m
Screen Resolution
1600 x 900 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
(1) ATA Hitachi HDS72101 SCSI Disk Device (
PSU
300W Stock
Case
Stock HP Dv7T
Cooling
1 Case Fan; 1 stock CPU cooler
Antivirus
MS Security Essentials
Browser
Google Chrome/Chromium
I don't remember it off hand, but I think there's a program launcher or command line that can set the affinity when the program is run. A search of softpedia shows this command line utility that seems close to what I'm remembering
ProcAff Free Download

For AHK you could do something in psudocode like
if process exists name
kill process,
run command line app that starts it with affinity

instead of doing it the macro way

( edit: looking at the app's options you can just change affinity instead of killing it etc.. )
 

My Computer

Computer Manufacturer/Model Number
HP Media Center
OS
Windows 7 32 bit
CPU
AMD 5200+ dual core
Memory
2 GB
Graphics Card(s)
NVidia GeForce 6150SE 128 MB
Monitor(s) Displays
CRT
Screen Resolution
1280x1024
Hard Drives
500 GB Sata internal :

SIIG USB 3.0 docking stations w/WD Caviar Black 6 Gb/s drives
Keyboard
PS/2
Mouse
PS/2 Wheel Mouse
Other Info
SIIG USB 3.0 PCIexpress card.
No need for 3rd party apps.
Command line will do it.

Open cmd prompt
type START /? and it enter
the switch of interest is /AFFINITY

A simple text batch file should be all you need to start an app at the desired affinity.

 
Last edited:

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Employer provided Dell Latitude
OS
W7 Pro SP1 64bit
CPU
i7
Memory
8GB
Graphics Card(s)
Intel HD Graphics
Hard Drives
crappy SSD
Antivirus
Employer mandated Symantec Endpoint Protection
Browser
Pale Moon 64bit, IE11 64bit & Chrome 64bit
No need for 3rd party apps.
Command line will do it.

Open cmd prompt
type START /? and it enter
the switch of interest is /AFFINITY

A simple text batch file should be all you need to start an app at the desired affinity.

Right, but if the app is already running then you're back to kill, then start etc..
If the batch is to be run only on the user's system then I see no problem with 3rd party software. However, if it's a homework assignment.... :)
 

My Computer

Computer Manufacturer/Model Number
HP Media Center
OS
Windows 7 32 bit
CPU
AMD 5200+ dual core
Memory
2 GB
Graphics Card(s)
NVidia GeForce 6150SE 128 MB
Monitor(s) Displays
CRT
Screen Resolution
1280x1024
Hard Drives
500 GB Sata internal :

SIIG USB 3.0 docking stations w/WD Caviar Black 6 Gb/s drives
Keyboard
PS/2
Mouse
PS/2 Wheel Mouse
Other Info
SIIG USB 3.0 PCIexpress card.
Hey thanks guys. Some great ideas there.
There is one caveat though, that prevents me from implementing them. I'm not sure it's 100% solvable:

It's an online game, that launches when I select a server from a 3rd party app. so I can't do the kill process-re-launch thing, because it will lose the server's IP.
It also means I'm not using a shortcut to the game's .exe.


I think the most reliable way is still through AHK - make sure the processes in task manager are sorted by name, count how many times I need to click the first letter so my process will be the top one, hope that no other processes with the same first letter are running, and simulate the mouse movements to set the affinity. Awkward!


I'll update you guys soon.
 

My Computer

OS
Win7 Pro SP1 64
CPU
Intel i7 860
Motherboard
Gigabyte GA-P55M-UD2 P55
Memory
Transcend 2GB DDR3 133
Graphics Card(s)
ATI Radeon 5770
Sound Card
M-Audio Profire 610
Okay got it!


EDIT: Doesn't work, refined code below.





It works, only if I don't have any additional "f" process running. Which I usually don't.
Thanks.
 
Last edited:

My Computer

OS
Win7 Pro SP1 64
CPU
Intel i7 860
Motherboard
Gigabyte GA-P55M-UD2 P55
Memory
Transcend 2GB DDR3 133
Graphics Card(s)
ATI Radeon 5770
Sound Card
M-Audio Profire 610
No need for 3rd party apps.
Command line will do it.

Open cmd prompt
type START /? and it enter
the switch of interest is /AFFINITY

A simple text batch file should be all you need to start an app at the desired affinity.

Right, but if the app is already running then you're back to kill, then start etc..
If the batch is to be run only on the user's system then I see no problem with 3rd party software. However, if it's a homework assignment.... :)
That 3rd party app might indeed be better for the OP's situation since the app is already running. There might be a way to do it with start switches, but it is probably not worth the effort to figure out.

On XP, I used an add-on to task manager called PRIO. It was not very stable, once I found a version that worked I stuck with it. But you could set both Affinity and Priority levels for most any process and it would remember them for you. The next time that the app started, the process would use the settings that you last had the PRIO app remember.

But that was not the main reason why I used PRIO, it added a services tab to task manager and a TCP/IP tab that was like netstat outputs.



Okay got it!
~~~
It works, only if I don't have any additional "f" process running. Which I usually don't.
Thanks.
You can send more than one key to the Task Manager window to select a process. Keys sent in rapid susession are interpreted as refinements of the item to be selected, not other processes to locate. e.g. one can send "CL" to locate CLOCK.exe. The "L" should not take the selection down to processes that start with "L".

I would suggest that you try sending the complete name of the process to the Task Manager window. That works for me using AutoIt, it should work for you using AHK. (AHK is a fork of AutoIt.) I've used both AHK and AutoIt. I prefer the AutoIt app and script editor, but I don't like the AutoIt forum :-(

Also, most anything that you can do with mouse clicks can be done with sending keystrokes. Keystrokes are usually easier to replicate than mouse click locations.

For example:
Shift+F10 is the same as right-click in most cases.
You can use the arrow up or arrow down to select items from the context menu - or better yet, send keystrokes.

If you really want to dive into this - then you would call the native Windows Application Programming Interface (API) and set the Affinity that way... but that is beyond my skill level in AutoIt. You might find a post in AutoIt's forum where someone has already written a script to do just what you are doing - only they did it without interacting with any windows - via the API.
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Employer provided Dell Latitude
OS
W7 Pro SP1 64bit
CPU
i7
Memory
8GB
Graphics Card(s)
Intel HD Graphics
Hard Drives
crappy SSD
Antivirus
Employer mandated Symantec Endpoint Protection
Browser
Pale Moon 64bit, IE11 64bit & Chrome 64bit
No need for 3rd party apps.
Command line will do it.

Open cmd prompt
type START /? and it enter
the switch of interest is /AFFINITY

A simple text batch file should be all you need to start an app at the desired affinity.

Right, but if the app is already running then you're back to kill, then start etc..
If the batch is to be run only on the user's system then I see no problem with 3rd party software. However, if it's a homework assignment.... :)
That 3rd party app might indeed be better for the OP's situation since the app is already running. There might be a way to do it with start switches, but it is probably not worth the effort to figure out.

On XP, I used an add-on to task manager called PRIO. It was not very stable, once I found a version that worked I stuck with it. But you could set both Affinity and Priority levels for most any process and it would remember them for you. The next time that the app started, the process would use the settings that you last had the PRIO app remember.

But that was not the main reason why I used PRIO, it added a services tab to task manager and a TCP/IP tab that was like netstat outputs.



Okay got it!
~~~
It works, only if I don't have any additional "f" process running. Which I usually don't.
Thanks.
You can send more than one key to the Task Manager window to select a process. Keys sent in rapid susession are interpreted as refinements of the item to be selected, not other processes to locate. e.g. one can send "CL" to locate CLOCK.exe. The "L" should not take the selection down to processes that start with "L".

I would suggest that you try sending the complete name of the process to the Task Manager window. That works for me using AutoIt, it should work for you using AHK. (AHK is a fork of AutoIt.) I've used both AHK and AutoIt. I prefer the AutoIt app and script editor, but I don't like the AutoIt forum :-(

Also, most anything that you can do with mouse clicks can be done with sending keystrokes. Keystrokes are usually easier to replicate than mouse click locations.

For example:
Shift+F10 is the same as right-click in most cases.
You can use the arrow up or arrow down to select items from the context menu - or better yet, send keystrokes.

If you really want to dive into this - then you would call the native Windows Application Programming Interface (API) and set the Affinity that way... but that is beyond my skill level in AutoIt. You might find a post in AutoIt's forum where someone has already written a script to do just what you are doing - only they did it without interacting with any windows - via the API.

Hey thanks a lot man.
You're probably right about using the keyboard instead of simulating mouse clicks. The power of habits I guess.
And I don't think I have the time to dive into all this API stuff... even that code I've written was actually a waste of time. I just couldn't resist the challenge I set myself haha.
 

My Computer

OS
Win7 Pro SP1 64
CPU
Intel i7 860
Motherboard
Gigabyte GA-P55M-UD2 P55
Memory
Transcend 2GB DDR3 133
Graphics Card(s)
ATI Radeon 5770
Sound Card
M-Audio Profire 610

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self built custom
OS
64-bit Windows 11 Pro for Workstations
CPU
Intel i7-8700K OC'd to 5 GHz
Motherboard
ASUS ROG Maximus XI Formula Z390
Memory
64 GB (4x16GB) G.SKILL TridentZ RGB DDR4 3600 MHz
Graphics Card(s)
ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
Sound Card
Integrated
Monitor(s) Displays
2 x Samsung Odyssey G7 27"
Screen Resolution
2560x1440
Hard Drives
1TB Samsung 990 PRO M.2,
4TB Samsung 990 PRO PRO M.2,
TerraMaster F8 SSD Plus NAS
PSU
Seasonic Prime Titanium 850W
Case
Thermaltake Core P3
Cooling
Corsair Hydro H115i
Keyboard
Logitech wireless K800
Mouse
Logitech MX Master 4
Internet Speed
2 Gb/s Download and 100 Mb/s Upload
Antivirus
Malwarebyte Anti-Malware Premium
Browser
Google Chrome
Other Info
Logitech Z625 speaker system,
Logitech BRIO 4K Pro webcam,
HP Color LaserJet Pro MFP M477fdn,
APC SMART-UPS RT 1000 XL - SURT1000XLI,
Galaxy S23 Plus phone
This forum is awesome, truly great guys.
I actually don't like to overburden my context menu, but if I did it would be great.


The above code isn't correct, here's a complete one:


Code:
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

^space::
Run taskmgr.exe
Sleep 200 ; ms
IfWinExist Windows Task Manager
{
WinActivate
}
Send F
Sleep 500 ; ms
Send F
Sleep 500 ; ms

Click right 85, 140	;open affinity
Sleep 500 ; ms
Click 150, 328
Sleep 500 ; ms

Click 30, 85	;all proc
Sleep 500 ; ms
Click 30, 102	;0 V
Sleep 500 ; ms
Click 200, 300	;close
Sleep 500 ; ms

Click right 85, 140	;open affinity
Sleep 500 ; ms
Click 150, 328
Sleep 500 ; ms

Click 30, 102	; 0 X
Sleep 500 ; ms
Click 30, 119	;1 V
Sleep 500 ; m
Click 200, 300	;close
Sleep 500 ; ms

Click right 85, 140	;open affinity
Sleep 500 ; ms
Click 150, 328
Sleep 500 ; ms

Click 30, 119	;1 X
Sleep 500 ; m
Click 30, 136	;2 V
Sleep 500 ; m
Click 200, 300	;close
Sleep 500 ; ms

Click right 85, 140	;open affinity
Sleep 500 ; ms
Click 150, 328
Sleep 500 ; ms

Click 30, 136	;2 X
Sleep 500 ; m
Click 30, 153	;3 V
Sleep 500 ; m
Click 200, 300	;close
Sleep 500 ; ms

Click right 85, 140	;open affinity
Sleep 500 ; ms
Click 150, 328
Sleep 500 ; ms

Click 30, 153	;3 X
Sleep 500 ; m
Click 30, 170	;4 V
Sleep 500 ; m
Click 200, 300	;close
Sleep 500 ; ms

Click right 85, 140	;open affinity
Sleep 500 ; ms
Click 150, 328
Sleep 500 ; ms

Click 30, 170 	;4 X
Sleep 500 ; m
Click 30, 187	;5 V
Sleep 500 ; m
Click 200, 300	;close
Sleep 500 ; ms

Click right 85, 140	;open affinity
Sleep 500 ; ms
Click 150, 328
Sleep 500 ; ms

Click 30, 187	;5 X
Sleep 500 ; m
Click 30, 204	;6 V
Sleep 500 ; m
Click 200, 300	;close
Sleep 500 ; ms

Click right 85, 140	;open affinity
Sleep 500 ; ms
Click 150, 328
Sleep 500 ; ms

Click 30, 204 	;6 X
Sleep 500 ; m
Click 30, 221	;7 V
Sleep 500 ; m
Click 200, 300	;close
Sleep 500 ; ms

Click right 85, 140	;open affinity
Sleep 500 ; ms
Click 150, 328
Sleep 500 ; ms

Click 30, 221	;7 X
Sleep 500 ; m
Click 30, 85	;all proc
Sleep 500 ; ms
Click 200, 300	;close
Sleep 500 ; ms


WinClose Windows Task Manager
IfWinExist FA Forever 0.8.53
{
WinActivate
}
IfWinExist Forged Alliance
{
WinActivate
}
 

My Computer

OS
Win7 Pro SP1 64
CPU
Intel i7 860
Motherboard
Gigabyte GA-P55M-UD2 P55
Memory
Transcend 2GB DDR3 133
Graphics Card(s)
ATI Radeon 5770
Sound Card
M-Audio Profire 610
I would replace the 200 ms sleep with a winwait statement

Code:
#NoEnv
SendMode Input

Run taskmgr.exe
WinWait, Windows Task Manager
IfWinExist Windows Task Manager
{
WinActivate
}
Send Clock
Sleep 500
Send, +{F10}
Sleep 500
Send, a
Sleep 500
WinWait, Processor Affinity
IfWinExist Processor Affinity
{
WinActivate
}
Sleep 500
Send, {DOWN 2}
Send, {SPACE}
Send, {ENTER}
As you know, hard coding sleep statements is hard to get right since system response time can vary.

The code above also demonstrates:
...sending more of the process name (instead of sending two F keys)
...sending keystrokes (instead of using mouse clicks).


If you stick with AHK, I hope that you are using their customized editor:
http://www.autohotkey.net/~fincs/SciTE4AutoHotkey_3/web/

edit: it is kind of sad that the devs at AHK are still using AutoIt3 Window Spy
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Employer provided Dell Latitude
OS
W7 Pro SP1 64bit
CPU
i7
Memory
8GB
Graphics Card(s)
Intel HD Graphics
Hard Drives
crappy SSD
Antivirus
Employer mandated Symantec Endpoint Protection
Browser
Pale Moon 64bit, IE11 64bit & Chrome 64bit
Back
Top