home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "IDBAS_Priority"
- Option Explicit
- Public Enum ePriorityClass
- ePriorityClass_Normal = &H20
- ePriorityClass_Low = &H40
- ePriorityClass_High = &H80
- ePriorityClass_RealTime = &H100
- End Enum
-
- Private Const PROCESS_DUP_HANDLE = &H40
-
- Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
- Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
- Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
- Private Declare Function SetPriorityClass& Lib "kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long)
- Private Declare Function GetPriorityClass Lib "kernel32" (ByVal hProcess As Long) As Long
-
- Public Property Let Priority(priorityValue As ePriorityClass)
-
- Dim hProcess&
- Dim ret&, pid&
- pid = GetCurrentProcessId() ' get my proccess id
- ' get a handle to the process
- hProcess = OpenProcess(PROCESS_DUP_HANDLE, True, pid)
-
- If hProcess = 0 Then
- Err.Raise 2, "Let Priority", "Unable to open the source process"
- Exit Property
- End If
-
- ' change the priority
- ret = SetPriorityClass(hProcess, priorityValue)
- ' Close the source process handle
- Call CloseHandle(hProcess)
-
- If ret = 0 Then
- Err.Raise 4, "Let Priority", "Unable to close source handle"
- Exit Property
- End If
-
- End Property
- Public Property Get Priority() As ePriorityClass
- Dim hProcess&
- Dim ret&, pid&
- pid = GetCurrentProcessId() ' get my proccess id
- ' get a handle to the process
- hProcess = OpenProcess(PROCESS_DUP_HANDLE, True, pid)
-
- If hProcess = 0 Then
- Err.Raise 2, "Get Priority", "Unable to open the source process"
- Exit Property
- End If
-
- ' change the priority
- Priority = GetPriorityClass(hProcess)
- ' Close the source process handle
- Call CloseHandle(hProcess)
-
- If Priority = 0 Then
- Err.Raise 4, "Get Priority", "Unable to close source handle"
- Exit Property
- End If
- End Property
-
-