Retour sur Vérifier si un processus devient inactif et avertir si c'est le cas
Débutant en VBScript j'aurai souhaité si possible un commentaire plus détaillé sur la partie Loop du script "CheckMyProcessActif" que je rappelle
et concernant la version avec fichier journal ajouté qui correspond bien à mon application dans quel répertoire doit on trouver le fichier log?
Code:
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 ws,MyProcess
Set ws = CreateObject("WScript.Shell")
MyProcess = "Calc.exe"
Do
'On vérifie si le processus de la calculatrice ne tourne pas alors
'on l'exécute
If CheckProcess(MyProcess) = False then
ws.run MyProcess
else
'On fait une pause d'une minute et on continue dans notre boucle pour vérifier
'la présence ou non de notre processus (Dans notre cas = Calc.exe)
Pause(1)
End if
Loop
'***************************************************************************
Function CheckProcess(MyProcess)
Dim strComputer,objWMIService,colProcessList
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select Name from Win32_Process WHERE Name LIKE '" & MyProcess & "%'")
If colProcessList.count > 0 then
CheckProcess = MyProcess & " is running"
CheckProcess = True
MsgBox"is running"
else
CheckProcess = MyProcess & " is not running"
CheckProcess = False
MsgBox"is not running"
End if
Set objWMIService = Nothing
Set colProcessList = Nothing
End Function
'*****************************************************************************
Sub Pause(NSeconds)
Wscript.Sleep(NSeconds*1000*60)
End Sub
'********* |