79

Is there a Windows equivalent of the Unix command, nice?

I'm specifically looking for something I can use at the command line, and not the "Set Priority" menu from the task manager.

My attempts at finding this on Google have been thwarted by those who can't come up with better adjectives.

Massimiliano
  • 16,770
  • 10
  • 69
  • 112
Ryan Fox
  • 10,103
  • 5
  • 38
  • 48

4 Answers4

70

If you want to set priority when launching a process you could use the built-in START command:

START ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
      [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
      [/WAIT] [/B] [command/program] [parameters]

Use the low through belownormal options to set priority of the launched command/program. Seems like the most straightforward solution. No downloads or script writing. The other solutions probably work on already running procs though.

Stephen Pellicer
  • 1,543
  • 1
  • 15
  • 13
  • 9
    To make `start` behave even more like `nice`, use the `/WAIT` and `/B` options to make the terminal output go to the same window. – Albert Armea Sep 02 '14 at 17:52
  • However, this seems to completely delete your command history (both from the arrow keys and hitting F7). – Albert Armea Sep 02 '14 at 21:26
  • 3
    This still doesn't answer how to change the priority of running processes - the answer from duane (via VBScript) is currently the best answer for this. – Simon Sobisch Nov 11 '16 at 08:01
  • If you try to run something like `start /low "C:\Program Files\myprog.exe" param1 param2` you'll receive error "Windows cannot find 'param1'". The solution is to replace "C:\Program Files\..." with c:\progra~1\.. without quotes (DOS directory name). – Putnik Mar 23 '19 at 14:28
  • How to run in bash? For `start /LOW /B type ls` I get a popup: "cannot find B:/" – jaques-sam Jun 23 '23 at 09:14
10

If you use PowerShell, you could write a script that let you change the priority of a process. I found the following PowerShell function on the Monad blog:

function set-ProcessPriority { 
    param($processName = $(throw "Enter process name"), $priority = "Normal")

    get-process -processname $processname | foreach { $_.PriorityClass = $priority }
    write-host "`"$($processName)`"'s priority is set to `"$($priority)`""
}

From the PowerShell prompt, you would do something line:

set-ProcessPriority SomeProcessName "High"
user247702
  • 23,641
  • 15
  • 110
  • 157
Chris Miller
  • 4,809
  • 4
  • 33
  • 50
  • Notes: - don't include the ".exe" (maybe it was obvious for others, but it appears in the TaskManager and confused me). - Priorities are case-sensitive (first and only first letter is uppercase) – Raúl Salinas-Monteagudo Mar 23 '22 at 09:20
6

Maybe you want to consider using ProcessTamer that "automatize" the process of downgrading or upgrading process priority based in your settings.

I've been using it for two years. It's very simple but really effective!

ggasp
  • 1,490
  • 3
  • 15
  • 24
5

from http://techtasks.com/code/viewbookcode/567

# This code sets the priority of a process

# ---------------------------------------------------------------
# Adapted from VBScript code contained in the book:
#      "Windows Server Cookbook" by Robbie Allen
# ISBN: 0-596-00633-0
# ---------------------------------------------------------------

use Win32::OLE;
$Win32::OLE::Warn = 3;

use constant NORMAL => 32;
use constant IDLE => 64;
use constant HIGH_PRIORITY => 128;
use constant REALTIME => 256;
use constant BELOW_NORMAL => 16384;
use constant ABOVE_NORMAL => 32768;

# ------ SCRIPT CONFIGURATION ------
$strComputer = '.';
$intPID = 2880; # set this to the PID of the target process
$intPriority = ABOVE_NORMAL; # Set this to one of the constants above
# ------ END CONFIGURATION ---------

print "Process PID: $intPID\n";

$objWMIProcess = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2:Win32_Process.Handle=\'' . $intPID . '\'');

print 'Process name: ' . $objWMIProcess->Name, "\n";

$intRC = $objWMIProcess->SetPriority($intPriority);

if ($intRC == 0) {
    print "Successfully set priority.\n";
}
else {
    print 'Could not set priority. Error code: ' . $intRC, "\n";
}
Ryan Fox
  • 10,103
  • 5
  • 38
  • 48