Etat d'un processus

cs_nicolasheurtevin Messages postés 88 Date d'inscription samedi 8 février 2003 Statut Membre Dernière intervention 29 août 2006 - 24 oct. 2003 à 16:15
cs_ludo24 Messages postés 37 Date d'inscription lundi 20 octobre 2003 Statut Membre Dernière intervention 12 juillet 2007 - 24 oct. 2003 à 18:12
Bonjour,

Je cherche l'instruction qui permet, en fonction du numéro de processus, de savoir si celui-ci est actif ou non.

Merci

Nicolas

1 réponse

cs_ludo24 Messages postés 37 Date d'inscription lundi 20 octobre 2003 Statut Membre Dernière intervention 12 juillet 2007
24 oct. 2003 à 18:12
J'espere ke ça t'aidera:

Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long

Public Const MAX_PATH As Integer = 260
Public Const TH32CS_SNAPPROCESS As Long = 2&

Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szexeFile As String * MAX_PATH
End Type

Function FindProcess(Process2Find As String, Optional lngThreads As Long = 0) As Boolean
'= true if process found
'= false otherwise

' Process2Find shall not include the path
' Process2find should include the extension (".exe")
' Process2Find is not case sensitive
' lngThreads is output

Dim i As Integer
Dim hSnapshot As Long
Dim uProcess As PROCESSENTRY32
Dim r As Long
Dim strTmp As String
Dim Pos


FindProcess = False


'fill the DB snapshot
hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)

If hSnapshot = 0 Then Exit Function

uProcess.dwSize = Len(uProcess)
r = ProcessFirst(hSnapshot, uProcess)

Do While r

strTmp = uProcess.szexeFile
Pos = InStr(1, strTmp, Chr(0))
If Pos > 0 Then strTmp = Left(strTmp, Pos - 1)

'Windows Me/98/95: file name includes the path
Pos = InStr(1, strTmp, "")
Do While Pos > 0
strTmp = Right(strTmp, Len(strTmp) - Pos)
Pos = InStr(1, strTmp, "")
Loop

If LCase(strTmp) = LCase(Process2Find) Then

'*** voila: le process est trouvé

FindProcess = True

'*** je recupere le thread mais peut etre ke tu t'en fous.
lngThreads = uProcess.cntThreads
Exit Function
End If

r = ProcessNext(hSnapshot, uProcess)
Loop

End Function
0
Rejoignez-nous