cs_nessi
Messages postés24Date d'inscriptionlundi 16 décembre 2002StatutMembreDernière intervention 9 décembre 2003
-
16 mai 2003 à 18:06
ratala
Messages postés248Date d'inscriptionjeudi 3 février 2005StatutMembreDernière intervention22 juin 2008
-
13 juil. 2006 à 23:50
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.
ratala
Messages postés248Date d'inscriptionjeudi 3 février 2005StatutMembreDernière intervention22 juin 2008 13 juil. 2006 à 23:50
Genial ta source on peux avoir les handles des controles avec, je cherchait ça depuis longtemps.
cs_Steff
Messages postés34Date d'inscriptionvendredi 9 novembre 2001StatutMembreDernière intervention29 mars 2007 30 juin 2004 à 16:36
Très intéressant comme source à mon goût.
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
cs_nessi
Messages postés24Date d'inscriptionlundi 16 décembre 2002StatutMembreDernière intervention 9 décembre 2003 16 mai 2003 à 18:13
ya une grande partie de ton code qui sert à rien :
à 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.
cs_nessi
Messages postés24Date d'inscriptionlundi 16 décembre 2002StatutMembreDernière intervention 9 décembre 2003 16 mai 2003 à 18:06
Bon, c cool, mais le mieux, ce serait de COMMENTER un peu le code, voir de le segmenter un peu plus. Sinon c cool, ça marche :)
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