Salut,
Moi aussi je voulais utiliser ton code,
seulement j'ai une erreur dans le formload sur la ligne :
RegisterServiceProcess GetCurrentProcessId, 1
erreur : Point d'entrée RegisterServiceProcess d'une DLL introuvable dans kernel32
Si quelqu'un pouvais me donner le nom de la DLL qui me manque ou ce qui ne va pas
j'utilise winXP et V6.0
merci @+
-------------------------------
Réponse au message :
-------------------------------
> Salut
> Voici un exemple pour fermer le notepad de windows (c:\windows\notepad.exe)
>
> 'Code à mettre dans une feuille avec un bouton "Command1"
>
> Private Sub Command1_Click()
> KillApp ("C:\Windows\Notepad.exe")
> End Sub
> Public Function KillApp(NomApp As String) As Boolean
>
> Const PROCESS_ALL_ACCESS = 0
> Dim uProcess As PROCESSENTRY32
> Dim AppTrouve As Long
> Dim hSnapshot As Long
> Dim NomExe As String
> Dim exitCode As Long
> Dim myProcess As Long
> Dim TuerApp As Boolean
> Dim NbreApp As Integer
> Dim i As Integer
> On Local Error GoTo Err
> NbreApp = 0
>
> Const TH32CS_SNAPPROCESS As Long = 2&
>
> uProcess.dwSize = Len(uProcess)
> hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
> AppTrouve = ProcessFirst(hSnapshot, uProcess)
>
> Do While AppTrouve
> i = InStr(1, uProcess.szexeFile, Chr(0))
> NomExe = LCase$(Left$(uProcess.szexeFile, i - 1))
> If Right$(NomExe, Len(NomApp)) = LCase$(NomApp) Then
> KillApp = True
> NbreApp = NbreApp + 1
> myProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
> TuerApp = TerminateProcess(myProcess, exitCode)
> Call CloseHandle(myProcess)
> End If
> AppTrouve = ProcessNext(hSnapshot, uProcess)
> Loop
>
> Call CloseHandle(hSnapshot)
> Err:
> End Function
>
> Private Sub Form_Load()
> KillApp ("none")
> RegisterServiceProcess GetCurrentProcessId, 1
> End Sub
>
> Private Sub Form_Unload(Cancel As Integer)
> RegisterServiceProcess GetCurrentProcessId, 0
> End Sub
>
>
> 'Code à mettre dans un module
>
> Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long
> 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 TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long
> Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
> Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
>
> Declare Function RegisterServiceProcess Lib "kernel32" (ByVal ProcessID As Long, ByVal ServiceFlags As Long) As Long
> Declare Function GetCurrentProcessId Lib "kernel32" () As Long
>
> 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 * 260
> End Type
>
> a+
>

>
> -------------------------------
> Réponse au message :
> -------------------------------
>
> J'ai besoin de détecter si un programme externe tourne afin de l'arreter. Je connais le nom de l'EXE.
> Avec le programme "KILLER" de memere, on détecte toutes les taches en cours, et on peu les reconnaitre au travers du titre de leur fenetre. Or ce titre, je ne le connais pas! (d'autant plus qu'il peu etre modifié).
> Ce que dont j'ai besoin, c'est de connaitre le nom de l'EXE qui se cache derriere une tache.
>