Visual Basic Programming Code Examples Visual Basic > Other Code Examples Change to priority level of the current process Change to priority level of the current process If you want to change the priority level of the current process then use the code listed below. This is useful for processes which are not important and may take a long time to complete, or when you want to speed a process up. Option Explicit Private Const THREAD_BASE_PRIORITY_IDLE As Long = -15, THREAD_BASE_PRIORITY_LOWRT As Long = 15 Private Const THREAD_BASE_PRIORITY_MIN As Long = -2, THREAD_BASE_PRIORITY_MAX As Long = 2 Private Const THREAD_PRIORITY_LOWEST As Long = THREAD_BASE_PRIORITY_MIN, THREAD_PRIORITY_HIGHEST As Long = THREAD_BASE_PRIORITY_MAX Private Const THREAD_PRIORITY_BELOW_NORMAL As Long = (THREAD_PRIORITY_LOWEST + 1), THREAD_PRIORITY_ABOVE_NORMAL As Long = (THREAD_PRIORITY_HIGHEST - 1) Private Const THREAD_PRIORITY_IDLE As Long = THREAD_BASE_PRIORITY_IDLE, THREAD_PRIORITY_NORMAL As Long = 0 Private Const THREAD_PRIORITY_TIME_CRITICAL As Long = THREAD_BASE_PRIORITY_LOWRT Private Const HIGH_PRIORITY_CLASS As Long = &H80, IDLE_PRIORITY_CLASS As Long = &H40 Private Const NORMAL_PRIORITY_CLASS As Long = &H20, REALTIME_PRIORITY_CLASS As Long = &H100 Private Declare Function SetThreadPriority Lib "kernel32" (ByVal hThread As Long, ByVal nPriority As Long) As Long Private Declare Function SetPriorityClass Lib "kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long Private Declare Function GetThreadPriority Lib "kernel32" (ByVal hThread As Long) As Long Private Declare Function GetPriorityClass Lib "kernel32" (ByVal hProcess As Long) As Long Private Declare Function GetCurrentThread Lib "kernel32" () As Long Private Declare Function GetCurrentProcess Lib "kernel32" () As Long Sub Test() SetPriority THREAD_PRIORITY_LOWEST, IDLE_PRIORITY_CLASS End Sub 'The SetPriorityClass function sets the priority class for the specified process 'This value together with the priority value of each thread of the process 'determines each thread's base priority level. Sub SetPriority(ByVal lThreadPriority As Long, ByVal lClassPriority As Long) Dim hThread As Long, hProcess As Long 'retrieve the current thread and process hThread = GetCurrentThread hProcess = GetCurrentProcess 'Test the current priority 'Debug.Print "Current Thread Priority:" + Str$(GetThreadPriority(hThread)) 'Debug.Print "Current Priority Class:" + Str$(GetPriorityClass(hProcess)) 'set the new thread priority to "lowest" SetThreadPriority hThread, lThreadPriority 'set the new priority class to "idle" SetPriorityClass hProcess, lClassPriority 'Re-test the priority 'Debug.Print "Current Thread Priority:" + Str$(GetThreadPriority(hThread)) 'Debug.Print "Current Priority Class:" + Str$(GetPriorityClass(hProcess)) End Sub