Thread: Общие вопросы (General Questions)/How Can I Lower the Priority of a Process Using a Script?

How Can I Lower the Priority of a Process Using a Script?
Const BELOW_NORMAL = 16384str
Computer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colProcesses = objWMIService.ExecQuery _ 
   ("Select * from Win32_Process Where Name = 'Notepad.exe'")For Each objProcess in colProcesses 

objProcess.SetPriority(BELOW_NORMAL) Next

The script begins by defining a constant named BELOW_NORMAL and setting the value to 16384; as you might expect, we’ll use this constant later on to change the priority of Notepad to Below Normal. Are there other values you can use to assign a different priority to a process? Of course there are:

Priority Class

Value

Normal

32

Low

64

Real-time

128

High

256

Below Normal

16384

Above Normal

32768



Source



Re: How Can I Lower the Priority of a Process Using a Script?
This is PowerShell script:

Get-WmiObject Win32_process -filter 'name = "dfsrs.exe"' | foreach-object { $_.SetPriority(16384) }



Re: How Can I Lower the Priority of a Process Using a Script?
# Set priority of the DFSR process
# This process should already run
#
# Normal 32
# Low  64
# Real-time 128
# High 256
# Below Normal 16384
# Above Normal 32768
#
param(
$priority = 16384 ,
$CPUMask = 0xf
)

function Main
{

    trap [Exception] {
        write-host
        $error[0] | Format-List -Force
        exit 1; }


Get-WmiObject Win32_process -filter 'name = "dfsrs.exe"' | foreach-object { $_.SetPriority($priority) }

write-host "Priority of the process has been set ||| "

# Set Affinity
#
# 0xf = 1111 – a mask allowing use of only the first four processors
#
$dfsrSet = Get-Process -ProcessName  "dfsrs"
foreach ($calc in $dfsrSet) {$calc.ProcessorAffinity=$CPUMask}

write-host "Affinity for the process has been set"

}

. Main


$error.Clear()
exit 0