************************************************************
OUVERTURE D'UNE APPLICATION
FERMETURE DE L'APPLICATION DEPUIS LE PROGRAMME QUI L'A LANCE
************************************************************
Private Declare Function OpenProcess Lib "kernel32" ( _
ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long _
) As Long
'
Private Declare Function TerminateProcess Lib "kernel32" ( _
ByVal hProcess As Long, _
ByVal uExitCode As Long _
) As Long
Private Declare Function CloseHandle Lib "kernel32" ( _
ByVal hObject As Long) As Long
'
Private Const PROCESS_TERMINATE = &H1
Dim NumProcess As Long
Dim RC As Long
Dim hProcess As Long
'
Sub ouvrir()
NumProcess = Shell(Nom_fic, 1)
End sub
Sub fermer()
hProcess = OpenProcess(PROCESS_TERMINATE, -1&, NumProcess)
RC = TerminateProcess(hProcess, 0&)
RC = CloseHandle(hProcess)
End Sub
ShellExecute Me.hwnd, vbNullString, "mailto:KPDTeam@Allapi.net", vbNullString, "C:\Documents and Settings\gallo\Bureau", SW_SHOWNORMAL
KillProcessus "POWERPNT.exe"
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionon error goto erreur KillProcessus "POWERPNT.exe" end erreur: msgbox(err & vblf & err.description) on error resume next
'Attribute VB_Name = "processus" 'Option Compare Database Option Explicit '----------------------------------------------------------------------------------------------------------' ' déclaration des types utilisés '----------------------------------------------------------------------------------------------------------' 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 Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long '----------------------------------------------------------------------------------------------------------' ' déclaration des types utilisés '----------------------------------------------------------------------------------------------------------' Const MAX_PATH As Integer = 260 Private Type LUID LowPart As Long HighPart As Long End Type Private Type LUID_AND_ATTRIBUTES pLuid As LUID Attributes As Long End Type Private Type TOKEN_PRIVILEGES PrivilegeCount As Long TheLuid As LUID Attributes As Long End Type Private 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 '----------------------------------------------------------------------------------------------------------' ' Terminer un processus : fonction système à ne surtout pas comprendre !! '----------------------------------------------------------------------------------------------------------' Private Function ProcessTerminate(Optional lProcessID As Long, Optional lHwndWindow As Long) As Boolean 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 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 lRetVal = GetWindowThreadProcessId(lHwndWindow, lProcessID) End If If lProcessID Then lhThisProc = GetCurrentProcess OpenProcessToken lhThisProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, lhTokenHandle LookupPrivilegeValue "", SE_DEBUG_NAME, tLuid tTokenPriv.PrivilegeCount = 1 tTokenPriv.TheLuid = tLuid tTokenPriv.Attributes = SE_PRIVILEGE_ENABLED AdjustTokenPrivileges lhTokenHandle, False, tTokenPriv, Len(tTokenPrivNew), tTokenPrivNew, lBufferNeeded lhwndProcess = OpenProcess(PROCESS_TERMINAT, 0, lProcessID) If lhwndProcess Then ProcessTerminate = CBool(TerminateProcess(lhwndProcess, lExitCode)) Call CloseHandle(lhwndProcess) End If End If On Error GoTo 0 End Function '----------------------------------------------------------------------------------------------------------' ' trouver un processus en fonction de son nom placé en paramètre '----------------------------------------------------------------------------------------------------------' Public Function KillProcessus(ByVal sProcessNameExe As String) As String Dim i As Integer Dim hSnapshot As Long Dim uProcess As PROCESSENTRY32 Dim r As Long Dim NOM(1 To 100) Dim num(1 To 100) Dim NR As Integer Const TH32CS_SNAPPROCESS As Long = 2& NR = 0 hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&) ' faire un instantané des processus s'executant au moment voulu If hSnapshot = 0 Then Exit Function ' si y'a pas alors ça sert à rien de continuer uProcess.dwSize = Len(uProcess) ' initialisation de uProcess r = ProcessFirst(hSnapshot, uProcess) ' on met dans r le premier processus rencontré Do While r ' faire tant que y'a des processus dans la liste NR = NR + 1 ' incrémentation de l'indice NOM(NR) = uProcess.szexeFile ' rempli le tableau de noms de processus num(NR) = uProcess.th32ProcessID ' rempli le tableau d'ID de processus r = ProcessNext(hSnapshot, uProcess) ' on essaie de passer au processus suivant Loop For i = 1 To NR ' pour tous les processus listés If InStr(UCase(NOM(i)), UCase(sProcessNameExe)) <> 0 Then ' si c le bon ProcessTerminate (num(i)) ' on le nique Exit For ' et on sort (à enlever si on veut tuer tous les processus du nom sProcessNameExe End If Next i End Function ' fin
NumProcess = Shell(Nom_fic, 1), mais normalement ça devrait marché non?
taskkill /F /IM POWERPNT.exedans c: que j'ai appelé kill-her.bat
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long Const SW_SHOWNORMAL = 1 Dim i As Long Private Sub Form_Load() ShellExecute Me.hwnd, "open", "C:\Documents and Settings\gallo\Bureau\SARZEMAAA.ppsx", vbNullString, "C:\Documents and Settings\gallo\Bureau\SARZEMAAA.ppsx", SW_SHOWNORMAL DoEvents i = 0 Timer1.Enabled = True End Sub Private Sub Timer1_Timer() i = i + 1 If i = 15 Then Shell "c:\kill-her.bat", vbHide End End If End Sub
ShellExecute Me.hwnd, "open", "C:Documents and SettingsgalloBureauSARZEMAAA.ppsx", vbNullString, "C:Documents and SettingsgalloBureauSARZEMAAA.ppsx", SW_SHOWNORMAL
shell App & path &"SARZEMAAA.ppsx"
KillProcessus "POWERPNT.exe"
shell "cmd taskkill /F /IM POWERPNT.exe", vbhide 'pour cacher la fenêtre DOS