SetProcessPriorityBoost
The SetProcessPriorityBoost function enables or disables the priority boost for the calling process.
Parameters
| Parameter | Type | Description |
|---|---|---|
hProcess |
HANDLE |
A handle to the process for which to set the priority boost. This handle must have the PROCESS_SET_INFORMATION access right. The value returned by the current process (using GetCurrentProcess) is sufficient. |
bDisablePriorityBoost |
BOOL |
If this parameter is TRUE, priority boosts are disabled for the process.
If this parameter is FALSE, priority boosts are enabled for the process.
|
Return Value
If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
Priority Boost Behavior
By default, the system provides a priority boost to a process under certain conditions, such as when it moves from background to foreground. This boost temporarily increases the process's base priority level to improve its responsiveness.
Calling SetProcessPriorityBoost with bDisablePriorityBoost set to TRUE prevents the system from applying these automatic priority boosts. This can be useful for processes that require consistent, predictable execution times and should not be affected by sudden priority changes.
Conversely, setting bDisablePriorityBoost to FALSE restores the default behavior, allowing the system to grant priority boosts when appropriate.
It is important to use this function judiciously. Disabling priority boosts for all processes could negatively impact system responsiveness, especially for interactive applications.
Example
#include <windows.h>
#include <iostream>
int main() {
HANDLE hProcess = GetCurrentProcess();
// Disable priority boosts for the current process
if (SetProcessPriorityBoost(hProcess, TRUE)) {
std::cout << "Priority boosts have been disabled for this process." << std::endl;
} else {
std::cerr << "Failed to disable priority boosts. Error: " << GetLastError() << std::endl;
}
// ... perform time-critical operations ...
// Re-enable priority boosts (restore default behavior)
if (SetProcessPriorityBoost(hProcess, FALSE)) {
std::cout << "Priority boosts have been re-enabled for this process." << std::endl;
} else {
std::cerr << "Failed to re-enable priority boosts. Error: " << GetLastError() << std::endl;
}
// Close the process handle if it was not obtained via GetCurrentProcess()
// In this example, GetCurrentProcess() returns a pseudo-handle that does not need to be closed.
// CloseHandle(hProcess);
return 0;
}
Requirements
| Minimum supported client | Windows XP [desktop apps only] |
|---|---|
| Minimum supported server | Windows Server 2003 [desktop apps only] |
| Target Platform | Windows |
| Header | Winbase.h (include Windows.h) |
| Library | Kernel32.lib |
| DLL | Kernel32.dll |