Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1537 connectés 

  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  Comment arrêter un Process de Windows à partir de VB???

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Comment arrêter un Process de Windows à partir de VB???

n°287642
stage
Posté le 16-01-2003 à 14:27:52  profilanswer
 

Es-ce que quelqu'un sait comment arrêter un process de Windows en code avec VB
 
Merci

mood
Publicité
Posté le 16-01-2003 à 14:27:52  profilanswer
 

n°287645
Bloodymary​_
Posté le 16-01-2003 à 14:32:22  profilanswer
 

Ben tu peux pas  
Faut passer par les API Win

n°287647
[SDF]Poire
Vive Grumly
Posté le 16-01-2003 à 14:33:19  profilanswer
 

beh tu peux utiliser les API en VB hein...
heureusement  :sarcastic:


---------------
Des bons sites pour Delphi? http://forum.hardware.fr/forum2.php3?post=16838&cat=10 -- informaticien -- http://www.z0rglub.com/phpwebgallery/ -- Delphi :love:
n°287648
stage
Posté le 16-01-2003 à 14:33:28  profilanswer
 

comment tu fais sa??

n°287654
[SDF]Poire
Vive Grumly
Posté le 16-01-2003 à 14:44:53  profilanswer
 

un truc du genre :
 
const WM_CLOSE = &H10
 
Private Declare Function PostMessage Lib "user32" _
   Alias "PostMessageA" _
  (ByVal hwnd As Long, _
   ByVal wMsg As Long, _
   ByVal wParam As Long, _
   lParam As Long) As Long
 
PostMessage(handle, WM_CLOSE, null, null)


---------------
Des bons sites pour Delphi? http://forum.hardware.fr/forum2.php3?post=16838&cat=10 -- informaticien -- http://www.z0rglub.com/phpwebgallery/ -- Delphi :love:
n°287655
[SDF]Poire
Vive Grumly
Posté le 16-01-2003 à 14:45:18  profilanswer
 
n°287656
stage
Posté le 16-01-2003 à 14:47:20  profilanswer
 

ok Merci

n°287663
drasche
Posté le 16-01-2003 à 14:59:00  profilanswer
 

C'est moche ya pas de biblio-link pour VB.  Je m'en occupe?


---------------
Whichever format the fan may want to listen is fine with us – vinyl, wax cylinders, shellac, 8-track, iPod, cloud storage, cranial implants – just as long as it’s loud and rockin' (Billy Gibbons, ZZ Top)
n°287671
[SDF]Poire
Vive Grumly
Posté le 16-01-2003 à 15:07:01  profilanswer
 

drasche a écrit :

C'est moche ya pas de biblio-link pour VB.  Je m'en occupe?


C une bonne id, j'y ai déjà pensé...
mais il y a pas ennormément de bon lien à part google pour VB et la msdn...
 
Moi je m'occupe déjà de celui de Delphi  ;)  
 
 :hello:


---------------
Des bons sites pour Delphi? http://forum.hardware.fr/forum2.php3?post=16838&cat=10 -- informaticien -- http://www.z0rglub.com/phpwebgallery/ -- Delphi :love:
n°287698
drasche
Posté le 16-01-2003 à 15:41:22  profilanswer
 

bah je ferai une recherche pour l'occasion ;)
 
ok c vendu je m'en occupe en rentrant!
 :hello:


---------------
Whichever format the fan may want to listen is fine with us – vinyl, wax cylinders, shellac, 8-track, iPod, cloud storage, cranial implants – just as long as it’s loud and rockin' (Billy Gibbons, ZZ Top)
mood
Publicité
Posté le 16-01-2003 à 15:41:22  profilanswer
 

n°287703
[SDF]Poire
Vive Grumly
Posté le 16-01-2003 à 15:43:18  profilanswer
 

drasche a écrit :

bah je ferai une recherche pour l'occasion ;)
 
ok c vendu je m'en occupe en rentrant!
 :hello:  


G déjà fait des recherches  :cry:  
 
Delphi C bien [:zion]


---------------
Des bons sites pour Delphi? http://forum.hardware.fr/forum2.php3?post=16838&cat=10 -- informaticien -- http://www.z0rglub.com/phpwebgallery/ -- Delphi :love:
n°287805
SkullX
Posté le 16-01-2003 à 17:43:30  profilanswer
 

jsuis pratiqument pret a parier que c'est excel.exe que tu veux faire planter :P hehe non ?

n°287808
drasche
Posté le 16-01-2003 à 17:46:37  profilanswer
 

[SDF]Poire a écrit :


Delphi C bien [:zion]


oui jusque là je crois que c évident pour tout le monde ;)


---------------
Whichever format the fan may want to listen is fine with us – vinyl, wax cylinders, shellac, 8-track, iPod, cloud storage, cranial implants – just as long as it’s loud and rockin' (Billy Gibbons, ZZ Top)
n°287810
drasche
Posté le 16-01-2003 à 17:47:30  profilanswer
 

SkullX a écrit :

jsuis pratiqument pret a parier que c'est excel.exe que tu veux faire planter :P hehe non ?


multi spotted :o


---------------
Whichever format the fan may want to listen is fine with us – vinyl, wax cylinders, shellac, 8-track, iPod, cloud storage, cranial implants – just as long as it’s loud and rockin' (Billy Gibbons, ZZ Top)
n°287811
SkullX
Posté le 16-01-2003 à 17:48:09  profilanswer
 

'DANS TON PROJET VB
Public Function ProcessList()
'Va tuer le process Excel.exe seulement s'il est présent dans la liste des processus.
 Dim hSnapshot As Long
 Dim uProcess As PROCESSENTRY32
 Dim r As Long
 'On passe tous les processus actif sur la machine et si on trouve que celui de
 'Excel est ouvert, c'est alors qu'on Termine l'application. Tous les autres processus
 'resteront activés.
  hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
  If hSnapshot = 0 Then Exit Function
   uProcess.dwSize = Len(uProcess)
   r = ProcessFirst(hSnapshot, uProcess)
   
   Do While r
        If Mid(uProcess.szexeFile, 1, 9) = "EXCEL.EXE" Then
          'Procédure qui termine le processus.
          ProcessTerminate (uProcess.th32ProcessID)
        End If
        'On passe au processus suivant.
        r = ProcessNext(hSnapshot, uProcess)
    Loop
End Function
 
'DANS UNE MODULE
'KILL PROCESSUS
Option Explicit
'Déclaration
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () 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 CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
 
'Déclaration de Type.
Private Type LUID
LowPart As Long
HighPart As Long
End Type
 
'Déclaration de Type.
Private Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type
 
'Déclaration de Type.
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
TheLuid As LUID
Attributes As Long
End Type
 
'Constante
Public Const MAX_PATH As Integer = 260
'Constante
Public Const TH32CS_SNAPPROCESS As Long = 2&
 
'Type
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
 
'Fonction
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
 
'Fonction ProcessTerminate
Function ProcessTerminate(Optional lProcessID As Long, Optional lHwndWindow As Long) As Boolean
'Variables locales
Dim lhwndProcess As Long
Dim lExitCode As Long
Dim lRetVal As Long
Dim lhThisProc As Long
Dim lhTokenHandle As Long
Dim tLuid As LUID
Dim tTokenPriv As TOKEN_PRIVILEGES, tTokenPrivNew As TOKEN_PRIVILEGES
Dim lBufferNeeded As Long
 
'Constantes
Const PROCESS_ALL_ACCESS = &H1F0FFF, PROCESS_TERMINAT = &H1
Const ANYSIZE_ARRAY = 1, TOKEN_ADJUST_PRIVILEGES = &H20
Const TOKEN_QUERY = &H8, SE_DEBUG_NAME As String = "SeDebugPrivilege"
Const SE_PRIVILEGE_ENABLED = &H2
 
On Error Resume Next
If lHwndWindow Then
'On va cherche le process ID du window handle.
lRetVal = GetWindowThreadProcessId(lHwndWindow, lProcessID)
End If
 
If lProcessID Then
'Donne la permission de tuer tous les processus.
lhThisProc = GetCurrentProcess
 
OpenProcessToken lhThisProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, lhTokenHandle
LookupPrivilegeValue "", SE_DEBUG_NAME, tLuid
'Set le nombre de privilèges a changer.
tTokenPriv.PrivilegeCount = 1
tTokenPriv.TheLuid = tLuid
tTokenPriv.Attributes = SE_PRIVILEGE_ENABLED
'Rend disponible le kill privilège dans l'accès token du processus.
AdjustTokenPrivileges lhTokenHandle, False, tTokenPriv, Len(tTokenPrivNew), tTokenPrivNew, lBufferNeeded
 
'Ouvrir le processus a tuer.
lhwndProcess = OpenProcess(PROCESS_TERMINAT, 0, lProcessID)
 
If lhwndProcess Then
'Obtient handle, kill le processus choisis.
ProcessTerminate = CBool(TerminateProcess(lhwndProcess, lExitCode))
Call CloseHandle(lhwndProcess)
End If
End If
On Error GoTo 0
End Function

n°288079
karlkox
Posté le 17-01-2003 à 09:59:25  profilanswer
 

Plus simple :
 
Call SendMessage(m_hWnd, WM_DESTROY, byval 0&, byval 0&)

n°288084
[SDF]Poire
Vive Grumly
Posté le 17-01-2003 à 10:05:17  profilanswer
 

WM_CLOSE C mieux  :D


---------------
Des bons sites pour Delphi? http://forum.hardware.fr/forum2.php3?post=16838&cat=10 -- informaticien -- http://www.z0rglub.com/phpwebgallery/ -- Delphi :love:
n°288406
karlkox
Posté le 17-01-2003 à 14:33:25  profilanswer
 

justement non, exemple : en envoyant WM_CLOSE, certains programmes (comme AOL), affiche un message comme quoi ca va fermer et il faut valider le plus souvent. Avec un WM_DESTROY, pas de pb ^_^

n°288410
[SDF]Poire
Vive Grumly
Posté le 17-01-2003 à 14:42:32  profilanswer
 

Oui mais C porc


---------------
Des bons sites pour Delphi? http://forum.hardware.fr/forum2.php3?post=16838&cat=10 -- informaticien -- http://www.z0rglub.com/phpwebgallery/ -- Delphi :love:
n°288423
drasche
Posté le 17-01-2003 à 14:57:20  profilanswer
 

[SDF]Poire a écrit :

Oui mais C porc


faut voir ton but, tu veux killer une application (auquel cas tu lui demandes pas son avis) ou tu lui demandes gentillement de bien vouloir se fermer?  Si on veut killer une application, ben oui c porc mais on fait pas d'omelette sans casser d'oeufs [:spamafote]


---------------
Whichever format the fan may want to listen is fine with us – vinyl, wax cylinders, shellac, 8-track, iPod, cloud storage, cranial implants – just as long as it’s loud and rockin' (Billy Gibbons, ZZ Top)
n°288425
[SDF]Poire
Vive Grumly
Posté le 17-01-2003 à 15:00:32  profilanswer
 

drasche a écrit :


faut voir ton but, tu veux killer une application (auquel cas tu lui demandes pas son avis) ou tu lui demandes gentillement de bien vouloir se fermer?  Si on veut killer une application, ben oui c porc mais on fait pas d'omelette sans casser d'oeufs [:spamafote]


Et sous win98 à force t'as un jouli blue screen


---------------
Des bons sites pour Delphi? http://forum.hardware.fr/forum2.php3?post=16838&cat=10 -- informaticien -- http://www.z0rglub.com/phpwebgallery/ -- Delphi :love:
n°288428
drasche
Posté le 17-01-2003 à 15:05:11  profilanswer
 

[SDF]Poire a écrit :


Et sous win98 à force t'as un jouli blue screen


ouais mais 98 c un OS grand public :whistle:


Message édité par drasche le 17-01-2003 à 15:05:31

---------------
Whichever format the fan may want to listen is fine with us – vinyl, wax cylinders, shellac, 8-track, iPod, cloud storage, cranial implants – just as long as it’s loud and rockin' (Billy Gibbons, ZZ Top)
n°288461
[SDF]Poire
Vive Grumly
Posté le 17-01-2003 à 15:47:42  profilanswer
 

drasche a écrit :


ouais mais 98 c un OS grand public :whistle:


C un OS trés répendu en prod encore  :sweat:  
 
d'ailleur là je suis sous win98 :cry:  
mais pas en prod :D en ingénieurie :sleep:


---------------
Des bons sites pour Delphi? http://forum.hardware.fr/forum2.php3?post=16838&cat=10 -- informaticien -- http://www.z0rglub.com/phpwebgallery/ -- Delphi :love:
n°288541
SkullX
Posté le 17-01-2003 à 17:02:47  profilanswer
 

le code que jai donné ocntionne pas sous 98 alors on s'en balance :P
 
y fonctionne sous 2000 et probablement XP

n°2231502
tk123
Posté le 21-06-2014 à 11:47:43  profilanswer
 

Slt SkullX,
j'ai essayé votre code pour terminer le processus de Excel et ça a bien marché! merce bcp à vous
Mais j'ai essayé le même code en modifiant EXCEL.EXE dans votre code en WINWORD.EXE ou autre pour terminer les autre processus autre que celle d'excel et ça n'a pas fonctioné!
Alors, j'ai besoin de votre aide comment faire pour terminer les autres processus!
Mrc d'avance et bonne continuation à vous!!

mood
Publicité
Posté le   profilanswer
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  Comment arrêter un Process de Windows à partir de VB???

 

Sujets relatifs
Comment creer un fichier .exe extractible à partir de fichiers ?question concernant Eclipse et windows NT
modifier un text a partir d'un JS (php inside aussi)[C#] docs s/ la prog Windows en C#
Récupérer le username windows dans une pageBoutton html qui ouvre une new windows
[C] arreter un programme proprementWindows : recevoir un evenement qui ne nous est pas destiné ?
Malloc sous Windowsfichiers bat et windows xp
Plus de sujets relatifs à : Comment arrêter un Process de Windows à partir de VB???


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR