78

有没有相当于 Unix 命令的 Windows 版本,很好

我专门寻找可以在命令行中使用的东西,而不是任务管理器中的“设置优先级”菜单。

我在谷歌上找到这个的尝试被那些想不出更好形容词的人所阻挠。

4

4 回答 4

69

如果要在启动进程时设置优先级,可以使用内置的START命令:

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

使用从低到低的选项来设置启动的命令/程序的优先级。似乎是最直接的解决方案。无需下载或编写脚本。不过,其他解决方案可能适用于已经运行的 procs。

于 2008-08-07T02:49:21.107 回答
9

如果您使用PowerShell,您可以编写一个脚本来更改进程的优先级。我在Monad 博客上找到了以下 PowerShell 函数:

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)`""
}

在 PowerShell 提示符下,您将执行以下操作:

set-ProcessPriority SomeProcessName "High"
于 2008-08-07T02:24:34.980 回答
7

也许您想考虑使用ProcessTamer根据您的设置“自动化”降级或升级进程优先级的过程。

我已经用了两年了。它非常简单但非常有效!

于 2008-08-07T01:21:06.837 回答
5

来自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";
}
于 2009-03-23T20:17:47.513 回答