6.1. Setting the Priority of a Process

Problem

You want to raise or lower the priority of a process. This is beneficial if you want to boost a CPU-starved process or limit a process that is hogging the CPU.

Solution

Using a graphical user interface

  1. Open Windows Task Manager (taskmgr.exe).

  2. Click on the Processes tab.

  3. If you do not see the process you want to set, be sure the box beside Show processes from all users is checked.

  4. Right-click on the target process, select Set Priority, and select the desired priority.

You can also accomplish the same task using the Sysinternals Process Explorer (procexp.exe) tool: right-click on the process and select Set Priority.

Using a command-line interface

With the start command, you can set the priority of a process when you initially run it. The following example shows how to create a process with a high priority:

> start /HIGH <ProgramPath>

The other valid priority options include /LOW, /NORMAL, /REALTIME, /ABOVENORMAL, and /BELOWNORMAL.

Using VBScript

' This code sets the priority of a process Const NORMAL = 32 Const IDLE = 64 Const HIGH_PRIORITY = 128 Const REALTIME = 256 Const BELOW_NORMAL = 16384 Const ABOVE_NORMAL = 32768 ' ------ SCRIPT CONFIGURATION ------ strComputer = "." intPID = 3280 ' set this to the PID of the target process intPriority = ABOVE_NORMAL ' Set this to one of the constants above ' ------ END CONFIGURATION --------- WScript.Echo "Process PID: " & intPID set objWMIProcess = GetObject("winmgmts:\\" & strComputer & _ "\root\cimv2:Win32_Process.Handle='" ...

Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.