VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Executes an application and sets the Priority Class for that application.

by Phil Scuderi (1 Submission)
Category: Windows System Services
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 1st January 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Executes an application and sets the Priority Class for that application.

API Declarations


'Use it and give it out to anyone'

Option Explicit

Public Declare Function SetPriorityClass Lib "kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Public Const PROCESS_ALL_ACCESS = &H1F0FFF

Public Const IDLE_PRIORITY_CLASS = &H40
Public Const BELOW_NORMAL_PRIORITY_CLASS = &H4000
Public Const NORMAL_PRIORITY_CLASS = &H20
Public Const ABOVE_NORMAL_PRIORITY_CLASS = &H8000
Public Const HIGH_PRIORITY_CLASS = &H80
Public Const REALTIME_PRIORITY_CLASS = &H100

Public Enum PRIORITY_CLASS
IDLE_PRIORITY
BELOW_NORMAL_PRIORITY
NORMAL_PRIORITY
ABOVE_NORMAL_PRIORITY
HIGH_PRIORITY
REALTIME_PRIORITY
End Enum

Public Function PriorityShell(PathName$, WindowStyle As VbAppWinStyle, Priority As PRIORITY_CLASS) As Long
Dim hInst, hProcess, dwPriorityClass As Long
Select Case Priority
Case IDLE_PRIORITY
dwPriorityClass = IDLE_PRIORITY_CLASS
Case BELOW_NORMAL_PRIORITY
dwPriorityClass = BELOW_NORMAL_PRIORITY_CLASS
Case NORMAL_PRIORITY
dwPriorityClass = NORMAL_PRIORITY_CLASS
Case ABOVE_NORMAL_PRIORITY
dwPriorityClass = ABOVE_NORMAL_PRIORITY_CLASS
Case HIGH_PRIORITY
dwPriorityClass = HIGH_PRIORITY_CLASS
Case REALTIME_PRIORITY
dwPriorityClass = REALTIME_PRIORITY_CLASS
Case Else
dwPriorityClass = NORMAL_PRIORITY_CLASS
End Select
hInst = Shell(PathName, WindowStyle)
hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0&, hInst)
Call SetPriorityClass(hProcess, dwPriorityClass)
Call CloseHandle(hProcess)
PriorityShell = hInst
End Function

Rate Executes an application and sets the Priority Class for that application.




Download this snippet    Add to My Saved Code

Executes an application and sets the Priority Class for that application. Comments

No comments have been posted about Executes an application and sets the Priority Class for that application.. Why not be the first to post a comment about Executes an application and sets the Priority Class for that application..

Post your comment

Subject:
Message:
0/1000 characters