UnMage
Messages postés32Date d'inscriptionsamedi 26 juin 2004StatutMembreDernière intervention15 novembre 2004 1 sept. 2004 à 14:38
Ouip désolé j'avais mis tout ça vite fait j'étais assez pressé.
cs_YaNn0u
Messages postés48Date d'inscriptionlundi 6 janvier 2003StatutMembreDernière intervention27 avril 2005 31 août 2004 à 15:14
Donc voici le code qui marche.. dans un module :
------------------------------
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal Classname As String, ByVal WindowName As String) As Long
Public Declare Function ReadProcessMem Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByRef lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Public Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
-------------------------------------------
dans une form :
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Function CloseWindowClient(gamewindowtext As String)
Dim hwnd As Long
Dim pid As Long
hwnd = FindWindow(vbNullString, gamewindowtext)
GetWindowThreadProcessId hwnd, pid
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
GetExitCodeProcess hProcess, nRet
Call TerminateProcess(hProcess, nRet)
Call CloseHandle(hProcess)
End Function
Private Sub Command1_Click()
Call CloseWindowClient("Sans titre - Bloc-notes")
End Sub
---------------------------------
WiP
cs_YaNn0u
Messages postés48Date d'inscriptionlundi 6 janvier 2003StatutMembreDernière intervention27 avril 2005 31 août 2004 à 14:45
Je râle pas, je l'informe d'un oubli.. Perso ca me gêne pas je l'avais déjà sur un autre code mais c'est pour les autres visiteurs !
Renfield
Messages postés17287Date d'inscriptionmercredi 2 janvier 2002StatutModérateurDernière intervention27 septembre 202174 31 août 2004 à 08:17
vous allez pas raler pour quelques declarations d'API manquantes ?
un peu de recherche , ca fait de mal a personne !
UnMage, dommage que tu aies deux lignes qui ne se rapportent pas a la fonction "generique" de fermeteure d'application, et qu'il n'y aies pas de gestion d'erreur (app non trouvée...) :
Private Function CloseWindowClient(gamewindowtext As String)
Dim hwnd As Long
Dim pid As Long
hwnd = FindWindow(vbNullString, gamewindowtext)
GetWindowThreadProcessId hwnd, pid
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
GetExitCodeProcess hProcess, nRet
Call TerminateProcess(hProcess, nRet)
Call CloseHandle(hProcess)
Unload Main <=====
Unload Browser <====
End Function
cs_YaNn0u
Messages postés48Date d'inscriptionlundi 6 janvier 2003StatutMembreDernière intervention27 avril 2005 31 août 2004 à 03:51
il manque findwindow hihi :x
Concretement, peux tu donner un exemple de ta source ?
UnMage
Messages postés32Date d'inscriptionsamedi 26 juin 2004StatutMembreDernière intervention15 novembre 2004 31 août 2004 à 03:45
Ah oui pardon :
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal Classname As String, ByVal WindowName As String) As Long
Private Declare Function ReadProcessMem Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByRef lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Il doit y en avoir en trop mais j'ai la flemme de trier..
cs_YaNn0u
Messages postés48Date d'inscriptionlundi 6 janvier 2003StatutMembreDernière intervention27 avril 2005 31 août 2004 à 03:06
marche pas unmage, il faudrait déclarer getwindowthreadprocess..
UnMage
Messages postés32Date d'inscriptionsamedi 26 juin 2004StatutMembreDernière intervention15 novembre 2004 7 août 2004 à 13:32
Moi j'utilise ça pour fermer un process de mon choix :
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
------------------------------------------------------------------
Private Function CloseWindowClient(gamewindowtext As String)
Dim hwnd As Long
Dim pid As Long
hwnd = FindWindow(vbNullString, gamewindowtext)
GetWindowThreadProcessId hwnd, pid
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
GetExitCodeProcess hProcess, nRet
Call TerminateProcess(hProcess, nRet)
Call CloseHandle(hProcess)
Unload Main
Unload Browser
End Function
-----------------------------------------------------------------------
Module01
-----------------------------------------------------------------------
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
J'ai récupéré TerminateProcess et GetExitCodeProcess de la source çi-dessus.
devsurf
Messages postés148Date d'inscriptiondimanche 13 octobre 2002StatutMembreDernière intervention13 novembre 2008 7 nov. 2003 à 01:08
C'est très sympa..
j'ai par contre un problème :
Tout fonctionne bien si l'application EXE n'a pas été lancée avant le demarage de notre code
Exemple :
Demarer word
Demarer notre source (ton prog vb)
A partir dela : Je n'arrive plus à maitriser le process dans ce cas
La fermeturte ne se fait pas , la création est alèatoire.
As tu une idée?
1 sept. 2004 à 14:38
31 août 2004 à 15:14
------------------------------
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal Classname As String, ByVal WindowName As String) As Long
Public Declare Function ReadProcessMem Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByRef lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Public Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
-------------------------------------------
dans une form :
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Function CloseWindowClient(gamewindowtext As String)
Dim hwnd As Long
Dim pid As Long
hwnd = FindWindow(vbNullString, gamewindowtext)
GetWindowThreadProcessId hwnd, pid
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
GetExitCodeProcess hProcess, nRet
Call TerminateProcess(hProcess, nRet)
Call CloseHandle(hProcess)
End Function
Private Sub Command1_Click()
Call CloseWindowClient("Sans titre - Bloc-notes")
End Sub
---------------------------------
WiP
31 août 2004 à 14:45
31 août 2004 à 08:17
un peu de recherche , ca fait de mal a personne !
UnMage, dommage que tu aies deux lignes qui ne se rapportent pas a la fonction "generique" de fermeteure d'application, et qu'il n'y aies pas de gestion d'erreur (app non trouvée...) :
Private Function CloseWindowClient(gamewindowtext As String)
Dim hwnd As Long
Dim pid As Long
hwnd = FindWindow(vbNullString, gamewindowtext)
GetWindowThreadProcessId hwnd, pid
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
GetExitCodeProcess hProcess, nRet
Call TerminateProcess(hProcess, nRet)
Call CloseHandle(hProcess)
Unload Main <=====
Unload Browser <====
End Function
31 août 2004 à 03:51
Concretement, peux tu donner un exemple de ta source ?
31 août 2004 à 03:45
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal Classname As String, ByVal WindowName As String) As Long
Private Declare Function ReadProcessMem Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByRef lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Il doit y en avoir en trop mais j'ai la flemme de trier..
31 août 2004 à 03:06
7 août 2004 à 13:32
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
------------------------------------------------------------------
Private Function CloseWindowClient(gamewindowtext As String)
Dim hwnd As Long
Dim pid As Long
hwnd = FindWindow(vbNullString, gamewindowtext)
GetWindowThreadProcessId hwnd, pid
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
GetExitCodeProcess hProcess, nRet
Call TerminateProcess(hProcess, nRet)
Call CloseHandle(hProcess)
Unload Main
Unload Browser
End Function
-----------------------------------------------------------------------
Module01
-----------------------------------------------------------------------
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
J'ai récupéré TerminateProcess et GetExitCodeProcess de la source çi-dessus.
7 nov. 2003 à 01:08
j'ai par contre un problème :
Tout fonctionne bien si l'application EXE n'a pas été lancée avant le demarage de notre code
Exemple :
Demarer word
Demarer notre source (ton prog vb)
A partir dela : Je n'arrive plus à maitriser le process dans ce cas
La fermeturte ne se fait pas , la création est alèatoire.
As tu une idée?