Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Process priority setting
#1
How can set/get the priority of a running program in the OS (ie: Normal, AboveNormal, Real Time). I found a command on MSDN but could not get it to work.
Matt B
Matt B
#2
Function SetProcessPriority

Code:
Copy      Help
;/
function hwnd priority [flags]

;Sets priority class of a process (running program).
;On failure generates error.
;hwnd - handle of some window of that process.
;flags - 1 hwnd is process id.
;priority - one of x_PRIORITY_x constants:
;;;def NORMAL_PRIORITY_CLASS 0x00000020 ;;normal, default
;;;def IDLE_PRIORITY_CLASS 0x00000040 ;;lowest
;;;def HIGH_PRIORITY_CLASS 0x00000080
;;;def REALTIME_PRIORITY_CLASS 0x00000100 ;;highest, dangerous
;;;def BELOW_NORMAL_PRIORITY_CLASS 0x00004000 ;;*
;;;def ABOVE_NORMAL_PRIORITY_CLASS 0x00008000 ;;*
;;;;* not supported on NT/98/Me


;EXAMPLES
;int hwnd=win("Notepad")
;SetProcessPriority hwnd IDLE_PRIORITY_CLASS
;;Eat all CPU time. Press Pause to stop.
;rep() int i=0
;;Try to work now in notepad...
;
;int pid=ProcessNameToId("notepad")
;if(!pid) end "the process is not running"
;SetProcessPriority pid BELOW_NORMAL_PRIORITY_CLASS 1



def PROCESS_SET_INFORMATION 0x0200
dll kernel32 #SetPriorityClass hProcess dwPriorityClass

int pid ph ok
if(flags&1) pid=hwnd; else GetWindowThreadProcessId(hwnd &pid)
ph=OpenProcess(PROCESS_SET_INFORMATION 0 pid); if(!ph) goto g1
ok=SetPriorityClass(ph priority)
;g1
if(!ok) _s.dllerror
if(ph) CloseHandle ph
if(!ok) end _s


December 27 2007
Fixed bug: flag 1 does not work.
#3
what about the opposite ?
GetProcessPriority

i would invoke trigger win+p to first get the actual priority
and then show a menu at mouse with other SetProcessPriority
options.
pi
#4
Function GetProcessPriority
Code:
Copy      Help
;/
function# hwnd [flags]

;Gets priority class of a process (running program).
;On failure generates error.


;Returns one of x_PRIORITY_x constants:
;;;def NORMAL_PRIORITY_CLASS 0x00000020 ;;normal, default
;;;def IDLE_PRIORITY_CLASS 0x00000040 ;;lowest
;;;def HIGH_PRIORITY_CLASS 0x00000080
;;;def REALTIME_PRIORITY_CLASS 0x00000100 ;;highest, dangerous
;;;def BELOW_NORMAL_PRIORITY_CLASS 0x00004000 ;;*
;;;def ABOVE_NORMAL_PRIORITY_CLASS 0x00008000 ;;*
;;;;* not supported on NT/98/Me


;hwnd - handle of some window of that process.
;flags - 1 hwnd is process id.


;EXAMPLE
;out "0x%X" GetProcessPriority(win("Notepad"))



int pid ph pr
if(flags&1) pid=hwnd; else GetWindowThreadProcessId(hwnd &pid)
ph=OpenProcess(PROCESS_QUERY_X_INFORMATION 0 pid); if(!ph) goto g1
pr=GetPriorityClass(ph)
;g1
if(!pr) _s.dllerror
if(ph) CloseHandle ph
if(!pr) end _s
ret pr
#5
I have Windows Vista, is there a Function for SetAffinity?
Taking on Quick Macros one day at a time
#6
Would be similar to SetProcessPriority, but instead of SetPriorityClass use SetProcessAffinityMask.
#7
It doesn't seem to work for me.

Function SetProcessPriority2
Code:
Copy      Help
;/
function hwnd priority [flags]

;Sets priority class of a process (running program).
;On failure generates error.
;hwnd - handle of some window of that process.
;flags - 1 hwnd is process id.
;priority - one of x_PRIORITY_x constants:
;;;def NORMAL_PRIORITY_CLASS 0x00000020 ;;normal, default
;;;def IDLE_PRIORITY_CLASS 0x00000040 ;;lowest
;;;def HIGH_PRIORITY_CLASS 0x00000080
;;;def REALTIME_PRIORITY_CLASS 0x00000100 ;;highest, dangerous
;;;def BELOW_NORMAL_PRIORITY_CLASS 0x00004000 ;;*
;;;def ABOVE_NORMAL_PRIORITY_CLASS 0x00008000 ;;*
;;;;* not supported on NT/98/Me

;EXAMPLES
;int hwnd=win("Notepad")
;SetProcessPriority hwnd IDLE_PRIORITY_CLASS
;;Eat all CPU time. Press Pause to stop.
;rep() int i=0
;;Try to work now in notepad...

;int pid=ProcessNameToId("notepad")
;if(!pid) end "the process is not running"
;SetProcessPriority pid BELOW_NORMAL_PRIORITY_CLASS 1


def PROCESS_SET_INFORMATION 0x0200
dll kernel32 #SetProcessAffinityMask hProcess dwPriorityClass

int pid ph ok
if(flags&1) pid=hwnd; else GetWindowThreadProcessId(hwnd &pid)
ph=OpenProcess(PROCESS_SET_INFORMATION 0 pid); if(!ph) goto g1
ok=SetProcessAffinityMask(ph priority)
;g1
if(!ok) _s.dllerror
if(ph) CloseHandle ph
if(!ok) end _s

I need to change the code for this so I can uncheck CPU 0 in the Set Affinity option but I couldn't find it in the msdn library.
Code:
Copy      Help
;;;def NORMAL_PRIORITY_CLASS 0x00000020 ;;normal, default
;;;def IDLE_PRIORITY_CLASS 0x00000040 ;;lowest
;;;def HIGH_PRIORITY_CLASS 0x00000080
;;;def REALTIME_PRIORITY_CLASS 0x00000100 ;;highest, dangerous
;;;def BELOW_NORMAL_PRIORITY_CLASS 0x00004000 ;;*
;;;def ABOVE_NORMAL_PRIORITY_CLASS 0x00008000 ;;*
Taking on Quick Macros one day at a time
#8
How do you call it. And how know that is does not work?
#9
I tried this

Macro
Code:
Copy      Help
int hwnd=win("Notepad")
SetProcessPriority2 hwnd IDLE_PRIORITY_CLASS

and I figured that if I change the "DILE_PRIORITY_CLASS" it might work.
Taking on Quick Macros one day at a time
#10
Argument #2 must be affinity mask, not priority class. Read SetProcessAffinityMask help. To turn off the first cpu in that process, the mask will be 2 (assuming there are 2 CPU).
#11
Quote:uncheck CPU 0 in the Set Affinity option

Where is the option? If it is an option in Control Panel, this function does not uncheck it. Don't know how.
#12
Task Manager --> Processes Tab --> Right click on Internet Explorer --> Set Affinity --> Then I get this, and I want to uncheck CPU 0, everytime internet explorer is opened.

[Image: 57118172.jpg]
Taking on Quick Macros one day at a time
#13
Function SetProcessAffinity
Code:
Copy      Help
;/
function hwnd affinityMask [flags] ;;flags: 1 hwnd is process id

;Sets affinity of a process (running program). It is which processors the process can use.
;On failure generates error.

;hwnd - handle of some window of that process.
;affinityMask - sum of flags, where flag 1 is for CPU0, flag 2 is for CPU1, flag 4 is for CPU2, flag 8 is for CPU3, .... For example, affinityMask 2 allows to use only CPU1.

;EXAMPLE
;SetProcessAffinity ProcessNameToId("notepad") 1 1 ;;let notepad use only CPU0


int pid ph ok
if(flags&1) pid=hwnd; else GetWindowThreadProcessId(hwnd &pid)
__Handle hp=OpenProcess(PROCESS_SET_INFORMATION 0 pid); if(!hp) goto g1
ok=SetProcessAffinityMask(hp affinityMask)
;g1
if(!ok) end _s.dllerror
#14
Macro
Trigger !ca"Internet Explorer provided by Dell" "IEFrame"     Help - how to add the trigger to the macro
Code:
Copy      Help
SetProcessAffinity ProcessNameToId("iexplore") 2 1

Works great, thanks alot.
Taking on Quick Macros one day at a time
#15
Too confusing. Please any other working, simple example how i can set priority for my macros on Win 7.
#16
Answer to myself question, may help someone else. Just simply add the following line to your macros.

Code:
Copy      Help
SetPriorityClass(GetCurrentProcess(),REALTIME_PRIORITY_CLASS)


Forum Jump:


Users browsing this thread: 1 Guest(s)