Ce petit programme réalisée grace aux API Windows reprend quelques sources du site AllApi.net
J'ai amélioré ces sources et j'ai réalisé un petit programme qui pourra compléter le gestionnaire de tâche...
Et qui sait peut être un jour le remplacer si je me décide à le finir ;)
Le code est peu commenté (en fait, pas du tout) mais j'ai eu la fleme ;)
A bientot !
Cyril
Source / Exemple :
' All in the ZIP
13 juil. 2006 à 23:50
30 juin 2004 à 16:36
J'ai repris juste un tout petit bout, la partie de création de liste et la partie de recherche d'un exe.
J'ai fait une lègère modif sur la lecture du uprocess afin d'avoir le szexename correct. Sans crochet et sans caractères inutile venant de la précédente lecture.
Ca donne ça :
uProcess.szExeFile = vbNullString
r = Process32First(hSnapShot, uProcess)
et mêm chose pour le next.
Voici mon module modifé qui permet en fait de voir si un exe est lancé :
Option Explicit
Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Public Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Public Const MAX_PATH As Integer = 260
Public Const TH32CS_SNAPHEAPLIST = &H1
Public Const TH32CS_SNAPPROCESS = &H2
Public Const TH32CS_SNAPTHREAD = &H4
Public Const TH32CS_SNAPMODULE = &H8
Public Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Public Const TH32CS_INHERIT = &H80000000
Public 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
Public Type aProc
aCount As Long
aProcess() As PROCESSENTRY32
End Type
Dim tmpProc As aProc
Private Function GetProcessExeName(tPID As Long) As String
Dim tProcName As String
Dim hSnapShot As Long
Dim uProcess As PROCESSENTRY32
Dim r As Long
'Takes a snapshot of the processes
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)
'set the length of our ProcessEntry-type
uProcess.dwSize = Len(uProcess)
'Retrieve information about the first process encountered in our system snapshot
uProcess.szExeFile = vbNullString
r = Process32First(hSnapShot, uProcess)
Do While r
If tPID = uProcess.th32ProcessID Then
GetProcessExeName = Trim(Replace(uProcess.szExeFile, Chr(0), ""))
Exit Function
End If
'Retrieve information about the next process recorded in our system snapshot
uProcess.szExeFile = vbNullString
r = Process32Next(hSnapShot, uProcess)
Loop
'close our snapshot handle
GetProcessExeName = "[Pas d'exécutable trouvé]"
CloseHandle hSnapShot
End Function
Private Sub GetProcessList()
Dim tProcName As String
Dim hSnapShot As Long
Dim uProcess As PROCESSENTRY32
Dim r As Long
'Takes a snapshot of the processes
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)
'set the length of our ProcessEntry-type
uProcess.dwSize = Len(uProcess)
'Retrieve information about the first process encountered in our system snapshot
uProcess.szExeFile = vbNullString
r = Process32First(hSnapShot, uProcess)
Do While r
tmpProc.aCount = tmpProc.aCount + 1
ReDim Preserve tmpProc.aProcess(tmpProc.aCount)
tmpProc.aProcess(tmpProc.aCount) = uProcess
'Retrieve information about the next process recorded in our system snapshot
uProcess.szExeFile = vbNullString
r = Process32Next(hSnapShot, uProcess)
Loop
'close our snapshot handle
CloseHandle hSnapShot
End Sub
Public Function IsExeLance(NomExe As String) As Boolean
Dim i As Integer
Dim stmp As String
IsExeLance = False
GetProcessList
For i = 0 To tmpProc.aCount - 1
stmp = GetProcessExeName(tmpProc.aProcess(i).th32ProcessID)
If UCase(stmp) = UCase(NomExe) Then
IsExeLance = True
Exit Function
End If
Next i
End Function
merci, ta source m'a bien aidé. note : 9
16 mai 2003 à 18:13
à partir de tHwnd = FindWindow(ByVal 0&, ByVal 0&).
modifie un peu la ligne ; cHwnd = FindWindow(ByVal 0&, ByVal 0&)
et supprime tout jusqu'au 'do';
et là, ça fait exactement la même chose.
16 mai 2003 à 18:06
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.