Sign in to follow this  
Followers 0
jennico

auto-priority.au3 gives priority to active windows's process automatically

8 posts in this topic

#1 ·  Posted (edited)

hi there,

played araound with the priority of current processes. i am not sure if this has been done before in this way. it's a little scriptie without cpu-usage and a very simple core.

why not write a script that generally gives priority to the active window's process ? in this way you could automatically speed up the process you are currently working on.

e.g. set priority to ie while surfing, to the game while gaming, to word when writing a letter, to wmp when rendering a videoclip, to nero when burning a cd, to emule when not doing anything else....

could be a good thing, you don't have to close other programs any more when your pc seems to slow down again, and so on.

tested this with success, it helps a lot to speed up heavy autoit scripts with lots of graphics inside (games). you can integrate it in your own script or put it in your startup folder, so you will always have it working.

please give me some feedback and tell me if you find any disadvantage. i found nothing bad in it so far.

j.

;--------------------------------------------;
;   auto-priority.au3 by jennico (c) 2008    ;
;--------------------------------------------;

Dim $old,$High[6],$Low[6]
Dim $Priority[6]=["Idle/Low","Below Normal","Normal","Above Normal","High","Realtime"] 

$highPriority=4; maybe 5 ?
$lowPriority=2; maybe 0 ?

;   if used in startup folder you might like to add....
;Sleep(300000)
;   make a sleep while booting and do not disturb.....

Opt("TrayMenuMode",3)
Opt("TrayOnEventMode",1)
TraySetIcon("pifmgr.dll",33)
$Hi=TrayCreateMenu("Set High Priority")
$Lo=TrayCreateMenu("Set Normal Priority")
For $i=5 To 0 Step -1
    $High[$i]=TrayCreateItem($Priority[$i],$Hi,-1,1)
        TrayItemSetOnEvent(-1,"_High")
        If $i=$highPriority Then TrayItemSetState(-1,1)
        If $i<$lowPriority Then TrayItemSetState(-1,128);disable
    $Low[$i]=TrayCreateItem($Priority[$i],$Lo,-1,1)
        TrayItemSetOnEvent(-1,"_Low")
        If $i=5 Then TrayItemSetState(-1,128); not recommended !!!
        If $i=$lowPriority Then TrayItemSetState(-1,1)
Next
TrayCreateItem("")
$Pause=TrayCreateItem("Set all Processes to Normal and Pause")
    TrayItemSetOnEvent(-1,"_Pause")
TrayCreateItem("")
$Exit=TrayCreateItem("Exit  (Sets all Processes to Normal)")
    TrayItemSetOnEvent(-1,"_Exit")

_Set($lowPriority); at first set all to normal/low

While 1;    now swap current process
    $PID=WinGetProcess("")
    If $PID>0 Then
        If $PID<>$old Then
            $text="2  [Paused] "
            If TrayItemGetState($Pause)=68 Then
                ProcessSetPriority($old,$lowPriority)
                ProcessSetPriority($PID,$highPriority)
                $text=$highPriority&"  ("&$Priority[$highPriority]&") "
            EndIf
            $array=ProcessList()
            If @error=0 Then
                For $i=1 To $array[0][0]
                    If $PID=$array[$i][1] Then
                        TraySetToolTip(" Active : "&$array[$i][0]&" "&@LF& _
                        " PID : "&$PID&@LF&" Priority : "&$text&@LF& _
                        " Total : "&$array[0][0]&" Processes "&@LF& _
                        " auto-priority.au3 by jennico (c) 2008 ")
                        ExitLoop
                    EndIf
                Next
            EndIf
            $old=$PID
        EndIf
    EndIf
    Sleep(100); or whatever
WEnd

Func _High()
    _Get($High,$highPriority)
EndFunc

Func _Low()
    _Get($Low,$lowPriority)
    _Set($lowPriority)
    For $i=0 To 4
        If TrayItemGetState($High[$i])=65 And $i<$lowPriority Then
            TrayItemSetState($High[$i],4)
            TrayItemSetState($High[$lowPriority],1)
            $highPriority=$lowPriority
        EndIf
        TrayItemSetState($High[$i],64+64*($i<$lowPriority))
    Next
EndFunc

Func _Pause()
    TrayItemSetState($Pause,1+3*(TrayItemGetState($Pause)=65))
    _Set()
EndFunc

Func _Exit()
    _Set()
    Exit
EndFunc

Func _Set($j=2)
    $array=ProcessList()
    If @error Then Return
    For $i=1 To $array[0][0]
        ProcessSetPriority($array[$i][1],$j)
    Next
EndFunc

Func _Get($t1,ByRef $t2)
    For $i=0 To 5
        If $t1[$i]=@TRAY_ID Then
            $t2=$i
            Return
        EndIf
    Next
EndFunc

;--------------------------------------------;
;   auto-priority.au3 by jennico (c) 2008    ;
;--------------------------------------------;
Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites



please leave a comment !!!

i just tried it with multiple ie windows. the active page is loading remarkably faster than the others !

Settings: High=4 Low=0

j.


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

if i remember well a comment of Valik, this is done automatically by Windows...

will test your script, maybe i'm wrong :)

nice job anyway.


-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]

Share this post


Link to post
Share on other sites

well, not sure about that. maybe it's a question of Windows settings.

at least, my script does make a difference (my laptop isn't the newest one, so it continiously works at its limits).

j.


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

so, i googled this issue. there are lots of similar tweaking tools. i think it makes sense.

By assigning a higher priority to more important tasks such as CD writing software or MP3 players, Windows ensures that critical tasks do not get interrupted by less important background tasks, like virus scanners or printer spoolers.

so, it's true that windows will adjust critical tasks, but .....

There is no automatic way to adjust the priority of a process in Windows using the default tools supplied by Microsoft. It is possible to adjust the current process priority but this setting is only valid for the current setting. Once the process gets killed, for example by closing the application or rebooting, it reverts the priority back to the default one.

But what if you want to do it automatically ? Say you happen to transcode videos every now and then and want that process to be below normal to continue working with your computer during the process. Or you would like to assign a higher process priority to a game that you like to play and that needs all the cpu cycles that it can get.

I can tell from personal experience that there are many applications where an automatic adjustment of the process priority would come in handy.

and there is another recommendation for default priority:

Try *lowering* the process priority. This may sound weird but give it at try anyway.

I have found that lowering the priority gives a much smoother overall performance of both the host and guest system.

so i recommend "idle/low" for low priority in my script ! try it out !

i think i will add some features like monitoring cpu usage and prevent tasks from overloading or completely locking. wouldn't it be nice to have process managing tool that automatically kills locking tasks ? what a relief ! you would never have to use ctr-alt-del anymore...(*sigh*) :)

j

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

i dont see too much difference on my machine (dual cores) but i think i does the same as the windows setup for foreground priority setup,

i will try it longer , see if i find a difference maybe which antivirus scanning or so..

apart from that : a watchdog to find blocking task would be a great addition..

Share this post


Link to post
Share on other sites

maybe on a new machine it does not make a lot of difference in general use. today i noticed a difference on watching a long videoclip. with high priority wmplayer starts and buffers a lot faster on my old laptop.

i will see if i can make cpu-exhausting example and measure the time.

j.


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

i made a testing script. before i tried it with a cpu-overloading script (99%), but this did not show any difference (probably because this kind of script has always priority).

so i decided to just measure a 'normal' process: mediaplayer. the test script measures the time between appearance of the wmp window and starting of the clip. furthermore, to make it more difficult, i chose a clip on a network computer. the clip has the 'normal' size of svcd (~800 mb).

my times:

low priority | high priority | time [sec]

Low........... | Low............ | 3.2

Low........... | Normal........ | 2.4

Normal...... | Realtime...... | 1.8

Low........... | Realtime..... | 1.6

without auto-priority.au3 | 2.08

the measurements are reproductable and seem logical. my script really speeds up tasks.

While 1
    WinWait("Windows Media Player")
    $begin=TimerInit()
    Do
    Until StringInStr(WinGetText("Windows Media Player"),"WMPVideoWindow")
    MsgBox(0,"Priority Test","Time: "&TimerDiff($begin)/1000&" sec.     ")
WEnd

instruction: start test script, then start a videoclip from context menu with mediaplayer and the passed time will show up when clip begins. then change auto-priority settings and restart same clip.

j.

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0