Lister les applications
Lister et/ou fermer des applications actives
Pour fermer une application, on écrira par exemple :
KillApp "Microsoft Excel - classeur.xls"
Option Compare Database Option Explicit '/ '/ A placer dans la partie déclarative '/ Declare Function EnumWindows Lib "user32" (ByVal wndenmprc As Long, _ ByVal lParam As Long) As Long Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _ (ByVal hwnd As Long, ByVal lpString As String, _ ByVal cch As Long) As Long Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, lParam As Any) As Long Private AppCible As String
La sub qui permet l'appel...
Public Sub KillApp(App_Cherchee As String) AppCible = App_Cherchee EnumWindows AddressOf EnumCallback, 0 End Sub
... à la fonction
Public Function EnumCallback(ByVal app_hWnd As Long, ByVal param As Long) As Long Dim buf As String * 256 Dim Titre As String Dim Longueur As Long Const WM_CLOSE = &H10 Longueur = GetWindowText(app_hWnd, buf, Len(buf)) Titre = Left$(buf, Longueur) If InStr(Titre, AppCible) <> 0 Then If MsgBox("Voulez vous fermer l'application " & Titre, _ vbQuestion + vbYesNo, "Fermeture") = vbYes Then 'ferme l'appli SendMessage app_hWnd, WM_CLOSE, 0, 0 End If End If 'Poursuit l'énumération EnumCallback = 1 End Function
Dernière modification : 31/10/2005 19:02
Catégorie : Les mémos - Administration
Page lue 5379 fois