1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
Public hProcess, nRet, Retour As Long
Const PROCESS_QUERY_INFORMATION = &H400
' Constantes des priorités (6 niveaux de priorités)
Public Const IDLE_PRIORITY_CLASS As Long = &H40 ' minimum
Public Const BELOW_NORMAL_PRIORITY_CLASS As Long = &H4000 ' normal -
Public Const NORMAL_PRIORITY_CLASS As Long = &H20 ' normal
Public Const ABOVE_NORMAL_PRIORITY_CLASS As Long = &H8000 ' normal +
Public Const HIGH_PRIORITY_CLASS As Long = &H80 ' haute
Public Const REALTIME_PRIORITY_CLASS As Long = &H100 ' maximum
'
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Declare Function SetPriorityClass Lib "kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long
' Constante paramètre de l'API OpenProcess
Private Const PROCESS_SET_INFORMATION As Long = &H200
' Defini la priorité d'un processus
Public Function SetProcessPriority(ByVal ProcessID As Long, ByVal Level As Long)
Dim hProcess As Long
' Ouvre en ecriture
hProcess = OpenProcess(PROCESS_SET_INFORMATION, 0, ProcessID)
' On définit la priorité
SetPriorityClass hProcess, Level
' On ferme le pointeur ouvert
CloseHandle hProcess
End Function
Sub launch_orcaflex()
' Pour lancer le programme :
Level = BELOW_NORMAL_PRIORITY_CLASS
Retour = Shell("C:\Program Files\Orcina\OrcaFlex\OrcaFlex.exe", 1)
' Pour Fermer le programme :
hProcess = OpenProcess(fdwAccess, False, Retour)
GetExitCodeProcess hProcess, nRet
SetProcessPriority hProcess, Level
Call CloseHandle(hProcess)
End Sub |
Partager