Results 1 to 9 of 9

Thread: [VB6] Process Priority Class

  1. #1

    Thread Starter
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Arrow [VB6] Process Priority Class

    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.
    Attached Files Attached Files
    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
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  2. #2
    Addicted Member
    Join Date
    Mar 2007
    Location
    India
    Posts
    227

    Re: Process Priority class

    This is a Great thing.

    Will it work with outside processes that is other software running on PC?

  3. #3

    Thread Starter
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Process Priority class

    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
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  4. #4

    Thread Starter
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Process Priority class

    EnumProcesses can provide the necessary ProcessIDs.
    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
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  5. #5

    Thread Starter
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Process Priority class

    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
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  6. #6
    Lively Member
    Join Date
    Aug 2011
    Posts
    66

    Re: Process Priority class

    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

  7. #7

    Thread Starter
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Process Priority class

    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
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  8. #8
    Lively Member
    Join Date
    Aug 2011
    Posts
    66

    Re: Process Priority class

    If I manage to run skyrim smoothly, I dont need other applications running at all
    Thanks!

  9. #9

    Thread Starter
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Process Priority class

    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.
    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
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width