The default priorities appear to be 8 for CPU and 5 for memory. Task scheduler gives them lower values like 6 and 3.
Process, Priority, ,N restores the CPU priority to 8, but memory priority is still 3 and performance of the script and any programs launched by the script is noticeably slower (eg. Chrome launch via URL link in my script GUI takes approximately 5 seconds; seems Chrome doesn't like the low memory priority of 3).
I found the priorities can be increased to 8 and 4 by creating the task with XML file <Priority>4</Priority> , however memory priority is still lower (4 instead of 5). Performance seems ok, but still I want the exact same priorities as if the user was just run the program normally as my script does some memory intensive things occasionally.
According to this it should be possible to do with a dllcall. Here is my unsuccessful attempt:
Code: Select all
Process, Exist ;get pid of script
h := DllCall("OpenProcess", "UInt", 0x0400, "Int", false, "UInt", ErrorLevel, "Ptr") ;get handle to the script
DllCall("SetPriorityClass", "Ptr", h, "UInt", 0x002) ;set priority class of script to PROCESS_BACKGROUND_MODE_END
DllCall("CloseHandle", "Ptr", h) ;close handle to script
Also I tried the command line processPriority.exe by user Charlie in that thread, but it returns error "unable to open process".
I've tried Reload aswell but it doesn't change the priorities. SingleInstance Off and then launch a new parallel instance should work, but then the UAC nag for admin privileges will pop up which defeats the whole purpose of using task scheduler in the first place, as it's the only way to silently run as admin at windows startup.
Thanks
edit:
<Priority>2</Priority> in the task scheduler XML is now giving me the default 8 and 5 values. However that's not how the documentation says it's supposed to work, which leads me to believe it's going to result in above normal values on other systems. Perhaps <Priority>2</Priority> in combination with Process, Priority, ,N will yield a safer result.