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.
Last edited by Bonnie West; Jan 23rd, 2013 at 03:26 PM.
Reason: Updated whole project
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
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.
Last edited by Bonnie West; Jan 7th, 2013 at 11:05 AM.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Last edited by Bonnie West; Jan 7th, 2013 at 11:09 AM.
Reason: Added link
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
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
Last edited by Bonnie West; Jan 7th, 2013 at 11:13 AM.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
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.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
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.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0