This class gets/sets the current process or thread's priority. It can also get/set other processes or threads' priorities, provided their ProcessID or ThreadID is supplied. A demo project à la Task Manager is included in the attachment.
Printable View
This class gets/sets the current process or thread's priority. It can also get/set other processes or threads' priorities, provided their ProcessID or ThreadID is supplied. A demo project à la Task Manager is included in the attachment.
This is a Great thing.
Will it work with outside processes that is other software running on PC?
I believe so, though I haven't tried. If Task Manager can do it, then so can any other process.
EDIT: Yes, it will work. I've tried it.
EnumProcesses can provide the necessary ProcessIDs.
Additionally, here are two more ways of passing the required ProcessID:
Code:Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hWnd As Long, Optional ByRef lpdwProcessId As Long) As Long
'Returns either the ProcessID or ThreadID from the given hWnd
Private Function GetProcessThreadID(ByVal hWnd As Long, Optional ByVal ReturnThreadID As Boolean) As Long
hWnd = GetWindowThreadProcessId(hWnd, GetProcessThreadID) 'Default return value is ProcessID
If ReturnThreadID Then GetProcessThreadID = hWnd 'If however, ThreadID was the one
End Function 'requested, then return it instead
'Shell's return value can be used as input for SetProcessPriorityClass
Private Sub Command1_Click()
With New clsPriorityClass
.SetProcessPriorityClass Shell("calc.exe", vbNormalFocus), IDLE_PRIORITY_CLASS
End With
End Sub
Private Sub Command2_Click()
With New clsPriorityClass
.SetProcessPriorityClass GetProcessThreadID(Me.hWnd), IDLE_PRIORITY_CLASS
End With
End Sub
Can it harm my proccessor if I change every time the proccess priority in, lets say, skyrim? or any other game?
Thanks for your project btw, I am going to use it :)
If your CPU can handle whatever game you throw at it, then there shouldn't be a problem if you manipulate that game's priority as often as you like. However, keep in mind that when setting a process' priority to HIGH_PRIORITY_CLASS or REALTIME_PRIORITY_CLASS, other running processes of lower priority will be adversely affected. Therefore, use this class with caution. :eek2:
If I manage to run skyrim smoothly, I dont need other applications running at all :D
Thanks!
You're welcome! :)
There are many applications that purportedly optimizes a game's performance, but the best and easiest way to do that is to turn off as many unnecessary processes as possible. You can do so by exiting the apps sitting in the tray.