Problems Setting Process Priorities RRS feed

  • Question

  • edit: This was my first attempt at scripting so I didn't really understand what I'd written, but the problem is real even if the first line of code wasn't

    I'm currently Transcoding my DVD collection to MP4s using Handbrake.  I like to set Handbrake to Realtime while I'm not using the computer and had created some powershell scripts for the purpose which I have attached to the macro keys on my G510.  I'm not sure it achieves much but it makes me feel the months it's taken so far have been a little more productive.  I used to have windows 7 ultimate 64bit with powershell 2.0 but have recently upgraded to windows 8 pro with powershell 3.0 and the scripts no longer work:

    SeIncreaseBasePriorityPrivilege (SE_INC_BASE_PRIORITY_PRIVILEGE)

    $p = Get-WmiObject win32_process -Filter "name='HandBrakeCLI.exe'"

    $s = "win32_process.handle=" + $p.handle


    This is the output:

    SE_INC_BASE_PRIORITY_PRIVILEGE : The term 'SE_INC_BASE_PRIORITY_PRIVILEGE' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Users\N'Djamena\Documents\Low.ps1:1 char:34
    + SeIncreaseBasePriorityPrivilege (SE_INC_BASE_PRIORITY_PRIVILEGE)
    +                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (SE_INC_BASE_PRIORITY_PRIVILEGE:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    __GENUS          : 2
    __CLASS          : __PARAMETERS
    __SUPERCLASS     :
    __DYNASTY        : __PARAMETERS
    __RELPATH        :
    __DERIVATION     : {}
    __SERVER         :
    __NAMESPACE      :
    __PATH           :
    ReturnValue      : 5
    PSComputerName   :

    'SE_INC_BASE_PRIORITY_PRIVILEGE' is no longer recognised and without it setPriority return 5 which I believe means access denied.

    I've looked but I haven't found any way to fix this.  Any pointers in the right direction would be appeciated.

    • Edited by N'Djamena Sunday, November 4, 2012 1:57 AM misdiagnosed the problem
    Friday, November 2, 2012 10:34 AM


  • You could always right-click the process in Task Manager and change its priority. That's how it's normally done.

    This utility advertises that it can manage process priorities for different kinds of processes automatically:


    (I found this by doing a quick search and know otherwise nothing about this software.)


    • Proposed as answer by Bill_Stewart Thursday, November 8, 2012 10:07 PM
    • Marked as answer by Bill_Stewart Monday, December 31, 2012 3:57 PM
    Tuesday, November 6, 2012 1:05 AM

All replies

  • I don't think this have ever worked in PS.

    Try instead starting process with elevated priority

    start /REALTIME HandBrakeCLI.exe

    Friday, November 2, 2012 12:24 PM

  • SeIncreaseBasePriorityPrivilege (SE_INC_BASE_PRIORITY_PRIVILEGE)
    $p = Get-WmiObject win32_process -Filter "name='HandBrakeCLI.exe'"
    $s = "win32_process.handle=" + $p.handle

    Is that the script?

    If so, there is no built-in or PowerShell command called 'SeIncreaseBasePriorityPrivilege'. That's the name of a user right. In addition, 'SE_INC_BASE_PRIORITY_PRIVILEGE' is missing the leading $ character required for PowerShell variables.

    I don't see how the first line would work in any version of PowerShell.


    Friday, November 2, 2012 2:22 PM
  • hmm, I can't post links, delete or replace the asterisks as appropriate.  Am I allowed to do that???

    ht * tp://msdn*microsoft*com/en-us/library/aa393587%28VS.85%29*aspx

    Sorry, I must have misunderstood what that was about.  I assumed it was a command that was needed before set priority was used.  Now that it's been pointed out I'm not even sure that's a page about powershell, maybe it was just pointing out the priority values.

    ht * tp://blogs*technet*com/b/heyscriptingguy/archive/2010/04/12/hey-scripting-guy-april-12-2010*aspx

    Near the bottom is the link -- To set the priority of a process, use the SetPriority method. --

    This is the first time I've used powershell for anything.  Well, I still need a script that will Change the priority of a process and this one used to work but doesn't anymore and I still don't know how to get it working.  Help please???

    I'll add that handbrake has been running in the background 24/7 since the day Ivybridge was released.  It already has an option to run the encoding process in realtime which comes into effect as it begins each new mp4.  My CPU is a 3770 which has been overclocked as far as it will go (41x100.5) and in 6 months I'm less than halfway through my DVD collection.  I've been slowly learning the Handbrake settings in the meantime and so some of my earlier attempts will have to be redone.  I need to squeeze everything I can from my computer but real-time plays havoc with the GUI and I need a simple way to switch it on and off.  Plus I just bought a Pioneer VSX-S500 that has problems initializing HDMI and having Handbrake messing with PnP really doesn't help.  Attaching these scripts to the macro keys on my keyboard is really quite important and I'm lost at the moment.
    • Edited by N'Djamena Friday, November 2, 2012 6:19 PM
    Friday, November 2, 2012 5:41 PM
  • Interesting, I moved the files out of the documents folder and into the windows folder and now they work.  Unfortunately they need to be run as administrator, which means I get the UAC popup box which wasn't necessary with Windows 7.  Is there any way I can avoid this?  And yes, I'm really showing my ignorance here, but it was working fine in Windows 7.

    (fwiw. I've deleted the - SeIncreaseBasePriorityPrivilege (SE_INC_BASE_PRIORITY_PRIVILEGE) - line)

    • Edited by N'Djamena Friday, November 2, 2012 8:17 PM
    Friday, November 2, 2012 8:15 PM
  • Hi,

    This works for me in Windows 7 and doesn't require administrative privileges:

    PS C:\> start-process calc.exe
    PS C:\> $p = get-wmiobject Win32_Process -filter "Name='calc.exe'"
    PS C:\> $p.SetPriority(64)

    When I look at the calc.exe process in Task Manager, it is set to Low priority (as expected) rather than Normal.


    • Edited by Bill_Stewart Saturday, November 3, 2012 7:08 PM
    • Proposed as answer by jrv Tuesday, May 21, 2019 11:34 PM
    Saturday, November 3, 2012 3:47 PM
  • I wrote that into a .ps1 file and, yes it worked.  So I took that exact text, removed the start-process line, replaced the 'calc.exe' with 'HandbrakeCLI.exe' then saved it and it wouldn't work without administrator privileges.  I can't remember but I'm pretty sure I didn't disable UAC in windows 7 and I'm sure as hell I never ran scripts as administrator.  Just as a thought I moved the script into the same folder and 'HandbrakeCLI.exe' and it still needed Admin to work.  Is it possible in that in windows 8, power shell 3.0 that a script needs administrator privileges to alter the priority of a process it didn't create itself???  If so, is disbling UAC is the only way I can get this working?

    The scripts definitely won't run from the documents directory, which is where they were in windows 7, is it possible there is somewhere I can put them that will make them work as intended?
    Sunday, November 4, 2012 1:43 AM
  • I'm fairly certain I'm dealing with new security measures rather than new scripting syntax or incompetent scripting.  So I guess the question ass, is there any way around it or do I just have to live with it?  Are there any settings I can change somewhere.  Does anyone know enough about Windows 8 to tell me?
    Sunday, November 4, 2012 2:06 AM
  • Sorry, I don't know enough details about the program your running or your computer to offer any other advice. It might be that the program you are running (HandbrakeCLI.exe) requires administrative privileges. If this is the case, you cannot bypass the UAC prompt, and this is by design.

    You might try asking the author of your software for advice on making it run better on your computer.


    Sunday, November 4, 2012 2:49 PM
  • First, can you show the entire script as you have it after having fixed the earlier issues, and error output (if any)?

    Second, if it isn't obvious from the script, are you running Handbrake directly or is it running from a scheduler or some other way so that it is potentially running from another account or with special privileges?

    The priority problem should be a Win8/PowerShell issue, but it seems to work fine from what I can tell. For example, with Win8/PS3, I can easily start notepad and then do this -

    gwmi Win32_Process | ?{$_.Name -eq "notepad.exe"} | %{$_.SetPriority(256)}

    The SetPriority returns a 0 result indicating success, and the priority value on a following query shows "high".
    Monday, November 5, 2012 3:52 PM
  • Sorry, it takes awhile to reply because I have to wait for an encode to finish before I can start experimenting.  I knew c++ 10 years ago but I've been dealing with medical problems since.  Adapting what I knew then to what's around now is a challenge.

    This is the Powershell script at the moment:

    $p = get-wmiobject Win32_Process -filter "name='HandBrakeCLI.exe'"

    And I've been running it through a VBS script to prevent the popup:

    command = "powershell.exe -nologo -command Realtime.ps1"
    set shell = CreateObject("WScript.Shell")
    shell.Run command,0

    HandbrakeCLI.exe is a part of Handbrake.  It means Handbrake'Command Line Interface'.exe.  It's possible to run this part directly from a batch file but I'm using the GUI program called Handbrake.exe.  I've checked and although CLI isn't run as admin Handbrake.exe does in fact require Administrator rights to run.  I modified the shortcut to run without them and the scripts were then able to change the priority, but in doing so handbrake was no longer able to start HandbrakeCLI with realtime priority.  And without Admin the scripts can't set the process to Realtime either.  And by the way, setting priority to 256 should set it to Realtime and not High.  I thought the first line, which apparently did nothing, was there to allow the scripts to set processes to Realtime.  Either something has changed in windows 8 or, heaven forbid, somehow I'd been missing the fact that neither handbrake or my scripts were actually setting the process to Realtime and I can't believe I'd be that oblivious.   I'm sure I would have looked in task manager to make sure everything was doing what it was supposed to but without a PC running Windows 7 I can't check.  I don't recall modifying the handbrake shortcut to run as admin, I'm not even sure how with the new start screen.  I learned how to edit the registry to run PS scripts as admin AFTER I installed Windows 8 and came across this problem.  Is there any way that my vbs script could have started powershell with admin privs?  I MUST have had task manager up and running when I first tested the macro keys and even without it, it's fairly obvious when Handbrake is set to Realtime.  At the moment I'd be happy for anything that would just get it working.  I can't remember if I'd disabled UAC on Win7, dealing with UAC prompts becomes habit and I don't really notice if they're there or not.  I've tried using the Application Compatibility Toolbox to let me run the scripts as admin without disabling UAC but it will only work on .exe files and even when I used it on Powershell.exe it didn't seem to do anything.  At the moment all I can think of is disabling UAC and using this vbs script:

    command = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
    params = " -nologo -command c:\windows\Realtime.ps1"
    Set objSh = CreateObject("Shell.Application")
    objSh.ShellExecute command, params , "", "runas", 0

    Which wasn't necessary before.  Ultimately I 'd like a script that I could leave running in the background that would capture the key presses.  That way I could leave UAC on and only be prompted once but that's a bit too much for me at the moment.  Writing a loop to detect when CLI is running and then setting the priority would solve the problem of Handbrake finishing a job and then starting a new one with realtime while I'm in the middle of something else.  Powershell will be fun when I get time to learn it properly.

    Monday, November 5, 2012 8:48 PM
  • So...do you still have a question, or...?


    Monday, November 5, 2012 9:13 PM
  • I want UAC.  At the moment I'm trying to figure out how to write the permanently running script.  I'm wondering how feasible it is.  Should I ask?  OK, if I do this would it be best to assign a modified keystroke to the macro keys (crtl/alt/r for Realtime) that a hidden powershell window could detect or is it possible to assign a script to a macro key that can send a signal to the main script???
    Tuesday, November 6, 2012 12:20 AM
  • Thanks all, it'll take time but I'll get there.

    Tuesday, November 6, 2012 1:04 AM
  • You could always right-click the process in Task Manager and change its priority. That's how it's normally done.

    This utility advertises that it can manage process priorities for different kinds of processes automatically:


    (I found this by doing a quick search and know otherwise nothing about this software.)


    • Proposed as answer by Bill_Stewart Thursday, November 8, 2012 10:07 PM
    • Marked as answer by Bill_Stewart Monday, December 31, 2012 3:57 PM
    Tuesday, November 6, 2012 1:05 AM
  • Ah, the simple solution.  The problem being my screen is routed through a rather fickle reciever and since the automatic powersaving option of turning the screen off also cuts off the sound I have to do it all manually.  If I want a sound but don't need the picture I turn off the monitor. if I need neither I turn off the receiver.  If I turn off the receiver then try to turn it back on again while handbrake is running in realtime it can take several minutes for everything to initailise properly and give me a picture.  My old receiver didn't do that, but my old receiver wouldn't fit under the monitor either.  That would be why I needed the shortcut keys in the first place.  On the plus side, in I look in devices, VSX-S500 is quite proudly included in the list, I didn't tell windows it was there.  New technology brings with it new problems.  Thanks, I'll look at the program and see if it does what I need it to.  If not it looks like I'm going to need to learn 'event' handling in powershell.  There are a bunch of questions I could ask but I'll do my best to find the answers myself before I start filling the forum with more beginners questions.


    Tuesday, November 6, 2012 1:43 AM
  • Hi,

    Keep in mind that this is a scripting forum. If you have any other scripting questions we can answer, please feel free to ask. Otherwise we need to mark an answer to this one and move on.


    Tuesday, November 6, 2012 4:22 PM
  • Investigating this and another person's issues with setting priority, I've discovered the following about attempting to set priority on Windows 7/8.

    (1) If running WITHOUT explicit elevation: Attempting to either run a process at Realtime priority or elevate a running process to Realtime priority from the process owner account will always return success; however, all it will really do is elevate the process to high. For a non-privileged account, a request for Realtime priority is interpreted as meaning just highest available.

    (2) From an explicitly elevated context - script, command prompt, or powershell prompt invoked as admin - it works, for any local account.

    Wednesday, November 7, 2012 12:33 AM
  • The name specified by MSDN is the name of a privilege that a process must have ("SeIncreaseBasePriorityPrivilege"; or for C++ developers, "SE_INC_BASE_PRIORITY_PRIVILEGE") -- this has nothing to do with PowerShell; it's not a PowerShell CmdLet or Function; the parenthesis that article uses are not some programmatic syntax, it's English syntax, providing you with multiple names by which you might know it.

    You could request the privilege via the RtlAdjustPrivilege method (you could import it in C# via):

    private static extern uint RtlAdjustPrivilege
        int Privilege,
        bool bEnablePrivilege,
        bool IsThreadPrivilege,
        out bool PreviousValue

    from what I can tell, SE_INC_BASE_PRIORITY_PRIVILEGE is defined as 14L (e.g. a long with the value of 14):



    Tuesday, May 21, 2019 11:10 PM
  • Not true.  See: https://docs.microsoft.com/en-us/windows/desktop/cimwin32prov/setpriority-method-in-class-win32-process

    Different kinds of privileges.  Bad choice of names by MS.

    Priority is a scalar.

    The question is bogus as changing this is completely unnecessary and Windows will not honor the upped value.

    Read the docs on proess ppriority.


    Tuesday, May 21, 2019 11:35 PM
  • Here is the easiest way to enable the privilege:


    but raising the priority of any process that does IO will have almost no effect.


    Tuesday, May 21, 2019 11:39 PM