1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| Option Explicit
dim titre_box, message, reponse, output
dim objArgs
titre_box = " test darrêt proprement d'un script "
message = "Veuillez choisir le type d'action à exécuter :" & vbCrLf & _
" Oui : je continue" & vbCrLf & _
" Non : je vais ailleurs" & vbCrLf & _
" Annuler : j'arrête !"
reponse = msgbox (message, vbYesNoCancel, titre_box)
if reponse = 6 then 'On a cliquè sur le bouton "OUI"
output =" J'ai cliqué sur Oui !"
elseif reponse = 7 then 'On a cliqué sur le bouton "Non"
output = " J'ai cliqué sur non !"
else ' On a cliqué sur le bouton "annuler"
output ="Je vais arrêter le programme "
'Cscript.quit ' => génère une erreur d'exécution Microsoft VBScript : Variable non définie: 'Cscript' (0x800A01F4)
'WScript.Quit ' => génère une erreur d'exécution Microsoft VBScript : Variable non définie: 'WScript' (0x800A01F4)
call StopMyScript
output ="si ce message s'affiche, c'est que le programme ne s'est pas arrêter !!"
end if
msgbox output
output ="reponse : " & reponse & vbtab & "=> je suis sortie du choix !"
output =" le programme continue ...."
'=================================
Sub StopMyScript()
Const NomProg1 = "Wscript.exe" , NomProg2 = "Cscript.exe"
Dim objWMIService, colProcessList, objProcess, strComputer
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process")
For Each objProcess in colProcessList
If LCase(objProcess.Name) = LCase(NomProg1) Or LCase(objProcess.Name) = LCase(NomProg2) Then
MsgBox objProcess.Name & " est en cours d'arrêt"
objProcess.Terminate()
Exit For
End If
Next
End Sub |
Partager