Sign in to follow this  
Followers 0
MSLx Fanboy

_ProcessGetPriority()

6 posts in this topic

#1 ·  Posted (edited)

First off, I'd like to thank Larry for his help in my first script utilizing DLLCalls (what a pain).

As the title says, the script gets the priority of a process based upon its PID. It would be nice to hopefully one day see this in the Process.au3 include file (if not in conjunction with ProcessSetPriority), but that's not important right now...

I'll separate the func from the example in a little while, but now...time to finally eat lunch :)

Update: Simplified return values and included separate test script.

ProcessGetPriority.zip

Edited by MSLx Fanboy

Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites



Cool. :) But could you make it so it returns the same number as used by ProcessSetPriority() like shown here:

0 - Idle/Low

1 - Below Normal (Not supported on Windows 95/98/ME)

2 - Normal

3 - Above Normal (Not supported on Windows 95/98/ME)

4 - High

5 - Realtime (Use with caution, may make the system unstable)


HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

yeah i agree.

a simple case/if statement could do that easy.

also what does the -1 do?

[edit]

did you want to do something like this:

#cs
    0 - Idle/Low
    1 - Below Normal (Not supported on Windows 95/98/ME)
    2 - Normal
    3 - Above Normal (Not supported on Windows 95/98/ME)
    4 - High
    5 - Realtime (Use with caution, may make the system unstable)
#ce


Func _ProcessGetPriority($v_PID = -1)
    
    If $v_PID <> - 1 Then
        
        $v_PID = Int($v_PID)
        
        If Not ProcessExists($v_PID) Then
            SetError(1)
            Return 0
        EndIf
        
        Local $h_DLL = DllOpen('kernel32.dll')
        $v_PID = DllCall($h_DLL, 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $v_PID)
        $v_PID = $v_PID[0]
        
    Else
        
        Local $h_DLL = DllOpen('kernel32.dll')
        
    EndIf
    
    Local $ai_ProcPri = DllCall($h_DLL, 'int', 'GetPriorityClass', 'int', $v_PID)
    
    If $ai_ProcPri = 0 Then
        SetError(2)
        Return 0
    EndIf
    
    If $v_PID <> - 1 Then DllCall($h_DLL, 'int', 'CloseHandle', 'int', $v_PID)
    
    DllClose($h_DLL)
    
    $ai_ProcPri = $ai_ProcPri[0]
    
    Select
        Case $ai_ProcPri = 0x00000040
            Return 0
        Case $ai_ProcPri = 0x00004000
            Return 1
        Case $ai_ProcPri = 0x00000020
            Return 2
        Case $ai_ProcPri = 0x00008000
            Return 3
        Case $ai_ProcPri = 0x00000080
            Return 4
        Case $ai_ProcPri = 0x00000100
            Return 5
    EndSelect
    
EndFunc;==> _ProcessGetPriority()
$Priority = _ProcessGetPriority(-1)
ConsoleWrite($Priority & @LF)

[/edit]

Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Share this post


Link to post
Share on other sites

Hehe, I looked at it earlier, and already did that. I just sent a nice copy to jdeb...who knows, it might be my first UDF... :)

I'll update the first post with a zip file of the func file and example script.


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

Useful script. This might come in handy.. :evil:

Cheers.. :)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

what about if u close it ? oh and i got a error with the old one at the for $i_Array if it was set to 4 on my machine it says exceeded origanil Value At line 9 ProcessSetPriority($i_notePad_pid, $a_RunLevels[$i_ArrayItem])

^

but What i did to check for a closed a window is throwing it out of wack. At the msgBox for NotePad Closed is $a_RunLevels[$i_ArrayItem] should be -1 instead it 0 and $i_ArrayItem is -1 :/

AHH NVm I SEE THE error Of my ways :/ it is at it should be

#include <_ProcessGetPriority.au3>
Dim $i_Priority_Level, $i_Notepad_PID, $i_ArrayItem
Dim $a_RunLevels[4] = [-1, 0, 2, 4];low, normal, high priorities
;Get Priority Level of this instance of AutoIt Scripting Engine
$i_Priority_Level = _ProcessGetPriority (@AutoItPID)
MsgBox(0, "AutoIt Script", "Should be 2: " & $i_Priority_Level)
$i_Notepad_PID = Run(@ComSpec & ' /c notepad.exe', '', @SW_HIDE)
For $i_ArrayItem = 0 To 3
    ProcessSetPriority($i_Notepad_PID, $a_RunLevels[$i_ArrayItem])
    $i_Priority_Level = _ProcessGetPriority ($i_Notepad_PID)
    if $i_Priority_Level = -1 then
MsgBox(0, "NotePad Closed", "is " & $a_RunLevels[$i_ArrayItem] & ": " & $i_Priority_Level)
Exit
else
    MsgBox(0, "Notepad Priority", "Should be " & $a_RunLevels[$i_ArrayItem] & ": " & $i_Priority_Level)
EndIf
Next
ProcessClose('notepad.exe')
Edited by WSCPorts

http://www.myclanhosting.com/defiasVisit Join and contribute to a soon to be leader in Custumized tools development in [C# .Net 1.1 ~ 2.0/C/C++/MFC/AutoIt3/Masm32]

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