Task Manager Processes

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Task Manager Processes

Post by Phil Pendlebury » Sun May 03, 2009 6:36 am

Hi all,

I a have a little utility that I wrote to turn affinity OFF and ON for a certain application. It;s to assist with a problem many poeple have with that application.

The MSched application needs to find the process name in Task Manager Processes and then right click. Then do some other stuff.

It works great for me. I have used screen grabs of the application name as it appears in Task Manager. Then the usual move mouse and so on.

I was just wondering if there is any other known way of getting the mouse to the application or even CHANGING (not SETTING) affinity for a certain application.

Note the capital letters above. I do not want command line to START an application with certain affinity. I already know how to do that but it does not have the desired effect.

Here is my current code to give you an idea of what I am doing:

Code: Select all

// COMPILE_OPTS|C:\Users\Phil\Downloads\P\auto_affinity.exe|C:\Program Files (x86)\Phil Pendlebury\MEAP\graphics\meapkeys.ico|CONSOLE=0|INCLUDES=1| /LOGFILE=\dev\nul /LOGFILE=\dev\nul /LOGFILE=\dev\nul /LOGFILE=\dev\nul
Press Ctrl
Press SHIFT
Press Esc
Wait>0.2
Release Ctrl
Release SHIFT
Release Esc
Wait>0.2
Let>XPFound=0
Let>VISTAFound=0
FindImagePos>%Script_dir%/taskxp.bmp,SCREEN,50,1,X,Y,XPFound
FindImagePos>%Script_dir%/taskvista.bmp,SCREEN,50,1,X,Y,VISTAFound

If>{(%XPFound% > 0) OR (%VISTAFound% > 0)}
  MouseMove>X_0,Y_0
Else
  GOTO>Exit
Endif


RClick
Wait>0.2
Send>a
Wait>0.2
WaitWindowOpen>Processor Affinity*
SetFocus>Processor Affinity*
Wait>0.2
SetCheckBox>Processor Affinity*,CPU 0,FALSE
Wait>0.2
PushButton>Processor Affinity*,OK
RClick
Wait>0.2
Send>a
Wait>0.2
SetCheckBox>Processor Affinity*,CPU 0,TRUE
Wait>0.2
PushButton>Processor Affinity*,OK
Wait>0.2
Press Esc
Wait>0.1
Release Esc

Label>Exit
What I need to try and do is eliminate the need for screen searching. As some people's application name is different or appears different.
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Wed May 06, 2009 11:18 am

No one any thoughts on this? :-)
Phil Pendlebury - Linktree

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed May 06, 2009 12:46 pm

Sorry, I have no experience with setting the processor affinity for a give n application. A quick look on the microsoft website brought up the SetProcessAffinityMask API function. Have you tried using that rather than popping windows?

One other thought. It looks to me like you're using FindImagePos> to determine the Operating System. Why not use the Macro Scheduler provided system variable OS_VER?

Later,
Dick

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed May 06, 2009 12:46 pm

This is untested, but does this help:

Code: Select all

VBSTART 
Function GetPID(pgm) 
  set wmi = getobject("winmgmts:") 
  sQuery = "select * from win32_process " & "where name='" & pgm & "'" 
  set processes = wmi.execquery(sQuery) 
  for each process in processes 
    getPID = process.ProcessID
  next 
End Function
VBEND

//Get ID of process
VBEval>GetPID("calc.exe"),pid

//Set Affinity
LibFunc>kernel32,SetProcessAffinityMask,res,pid,1
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Wed May 06, 2009 7:24 pm

JRL wrote:Sorry, I have no experience with setting the processor affinity for a give n application. A quick look on the microsoft website brought up the SetProcessAffinityMask API function. Have you tried using that rather than popping windows?

One other thought. It looks to me like you're using FindImagePos> to determine the Operating System. Why not use the Macro Scheduler provided system variable OS_VER?

Later,
Dick
Hi Dick,

Regarding OS, not really... There are two imaged (one for each OS).

The problem is that regardless of OS, everyone's Task Manager text can be slightly different.

So using Marcus's example the two images are of the words "calc" taken from each OS I have. But more to add the problem is that there are two or there different program names too.

Getting the OS will be a help though, with my existing method. Although I was hoping I could get away from using screen images at all.

:-)
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Wed May 06, 2009 7:27 pm

mtettmar wrote:This is untested, but does this help:

Code: Select all

VBSTART 
Function GetPID(pgm) 
  set wmi = getobject("winmgmts:") 
  sQuery = "select * from win32_process " & "where name='" & pgm & "'" 
  set processes = wmi.execquery(sQuery) 
  for each process in processes 
    getPID = process.ProcessID
  next 
End Function
VBEND

//Get ID of process
VBEval>GetPID("calc.exe"),pid

//Set Affinity
LibFunc>kernel32,SetProcessAffinityMask,res,pid,1
Hi Marcus,

Thanks for that. It is a little beyond me but I ran it anyway using calculator as an example and it seemed to do nothing.

As I am on Vista 64 I also tried using Firefox.exe which is a 32 bit process... Also nothing.

Bear in mind that affinity need to be turned OFF AND the On again for 1 CPU.

What I really need is a foolproof way of bringing up the programs affinity properties (from Task Manager) without using screen recognition of the program text.

I know this is long shot but thought I would ask.

Thanks guys.

:-)
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Wed May 06, 2009 7:30 pm

Just to explain further what my script does (above).

It opens Task Manager (Which must be set to view Processes)
It searches for one of two images. (A capture of the word calc.exe for example)
It then moves the mouse there and right clicks
It opens the affinity settings and disables affinity for CPU 0
It then enables it again.
Phil Pendlebury - Linktree

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed May 06, 2009 7:33 pm

Why not:

Code: Select all

Let>RP_WAIT=2
Run>taskmgr.exe
WaitWindowOpen>Windows Task Manager
Send>firefox.exe
Press MenuKey
Send>a
.. etc
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Wed May 06, 2009 8:33 pm

There you go Marcus. That will do the trick nicely.

I honestly never thought that would work because I thought that one key would, move to the next alphabetical item.

Thank you.

:) :) :)
Last edited by Phil Pendlebury on Wed May 06, 2009 9:05 pm, edited 1 time in total.
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Wed May 06, 2009 9:05 pm

And here's the finished script.

It requires an entry in an ini file to choose the application:

Code: Select all


ReadIniFile>%SCRIPT_DIR%\audioapp.ini,application,def_audioapp,audioapp

Let>RP_WAIT=2
Wait>0.5
Run>taskmgr.exe
WaitWindowOpen>Windows Task Manager
Send>%audioapp%
Press MenuKey
Send>a
Wait>0.2
Send>a
Wait>0.2
WaitWindowOpen>Processor Affinity*
SetFocus>Processor Affinity*
Wait>0.2
SetCheckBox>Processor Affinity*,CPU 0,FALSE
Wait>0.2
PushButton>Processor Affinity*,OK
Press MenuKey
Wait>0.2
Send>a
Wait>0.2
SetCheckBox>Processor Affinity*,CPU 0,TRUE
Wait>0.2
PushButton>Processor Affinity*,OK
Wait>0.2
Press Esc
Wait>0.1
Release Esc

Label>Exit
Phil Pendlebury - Linktree

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Wed May 06, 2009 9:30 pm

Hi Phil,

Thanks for posting your finished script, it may come in handy for others.
http://www.online-tech-tips.com/windows-xp/set-processor-cpu-affinity/ wrote:Another issue you might see is when running older applications on a dual core machine. Older applications will actually run slower and may start using up 100% of the CPU. You can go into the Processor Affinity dialog and un-check one of the cores so that the program uses only a single core.
Is the above your problem? And switching affinity off then on again... fixes it for a little while?

Just curious...
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Wed May 06, 2009 9:34 pm

jpuziano wrote:Hi Phil,

Thanks for posting your finished script, it may come in handy for others.
http://www.online-tech-tips.com/windows-xp/set-processor-cpu-affinity/ wrote:Another issue you might see is when running older applications on a dual core machine. Older applications will actually run slower and may start using up 100% of the CPU. You can go into the Processor Affinity dialog and un-check one of the cores so that the program uses only a single core.
Is the above your problem? And switching affinity off then on again... fixes it for a little while?

Just curious...
Kind of related to that but it also is due to problems with the software's own management of multi processors.

http://www.studionu.com/uadforums/viewt ... 11&t=11637

:-)
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Thu May 07, 2009 12:22 pm

Updated this today so you can adjust a few more things. So it will work with other languages etc.


autoaffinity.ini

Code: Select all

[application]
// Change this to the name of your application
// Exactly how it is written in Task Manager
def_audioapp=Firefox.exe

[taskmanager]
// The name of your Task manager Window
def_taskmanagername=Windows Task Manager

[affinity]
// The name of your Processor Affinity Dialog
def_processoraffinityname=Processor Affinity

[cpu]
// Which processor you want to turn on and off
def_processor=0
Script:

Code: Select all

ReadIniFile>%SCRIPT_DIR%\autoaffinity.ini,application,def_audioapp,audioapp
ReadIniFile>%SCRIPT_DIR%\autoaffinity.ini,taskmanager,def_taskmanagername,taskmanagername
ReadIniFile>%SCRIPT_DIR%\autoaffinity.ini,affinity,def_processoraffinityname,processoraffinityname
ReadIniFile>%SCRIPT_DIR%\autoaffinity.ini,cpu,def_processor,processor
Let>processoraffinityname=%processoraffinityname%*
Let>processor=CPU %processor%

Let>RP_WAIT=2
Wait>0.5
Run>taskmgr.exe
WaitWindowOpen>%taskmanagername%
Send>%audioapp%
Press MenuKey
Send>a
Wait>0.2
Send>a
Wait>0.2
WaitWindowOpen>%processoraffinityname%
SetFocus>%processoraffinityname%
Wait>0.2
SetCheckBox>%processoraffinityname%,%processor%,FALSE
Wait>0.2
PushButton>%processoraffinityname%,OK
Press MenuKey
Wait>0.2
Send>a
Wait>0.2
SetCheckBox>%processoraffinityname%,%processor%,TRUE
Wait>0.2
PushButton>%processoraffinityname%,OK
Wait>0.2
Press Esc
Wait>0.1
Release Esc

Label>Exit
Phil Pendlebury - Linktree

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts