J'ai mis le code dans une fonction (comme au début de ton script), ainsi tu n'avais plus qu'à la mettre à la fin du script et l'appeler au moment où
tu veux tuer ton process.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Function getSystemVar(VarName)
    Dim wss, env
    Set wss = CreateObject("WScript.Shell")
    Set env = wss.environment("process")
    getSystemVar = env(VarName)
End Function
 
Function KillProcessByName (NOM_PROCESS)
   Dim retour
   Dim strComputer
   Dim objWMIService
   Dim colItems
   Dim FSO
   Dim Ftxt
   Dim path
 
   path = "D:\Script_test\Log_test.log"
   retour = 0
   strComputer = "." 
   Set FSO = CreateObject("Scripting.FileSystemObject")
   Set Ftxt = FSO.OpenTextFile (path,8,true)
   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & NOM_PROCESS & "'",,48)
   If ColProcessList.count <> 0 Then
      retour = objProcess.Terminate()
      Ftxt.writeline (Year(date)) & vbTab & (Month(date)) & vbTab & (Day(date)) & vbTab & (time) & vbTab & (getSystemVar("COMPUTERNAME")) & vbTab & resultat1 & vbTab & resultat2 & vbTab & (PID) & vbTab & (terminal) & vbTab & resultat5 & vbTab & resultat4 & vbTab & return & vbTab & (gravite) & vbTab & resultat3 & vbTab &(getSystemVar("UNISON_JOBNUM")) & vbTab & (valeur) & vbTab & (message)
   Else
 
   Ftxt.writeline " le process n'est pas la"
   End If
 
   Ftxt.close()
 
   KillProcessByName = retour
End Function
 
'On recupere une partie dela chaine de caractere
 
resultat1 = Mid(getSystemVar("UNISON_SCHED"),2,3)
resultat2 = Mid(getSystemVar("UNISON_SCHED"),7,3)
resultat3 = Mid(getSystemVar("UNISON_SCHED"),5,3)
resultat4 = Mid(getSystemVar("UNISON_JOB"),14,43)
resultat5 = Mid(getSystemVar("USERNAME"),13.6)
 
 
 
Dim NOM_PROCESS
Dim retour
Dim args
Set args = WScript.Arguments
NOM_PROCESS= args(0)
 
retour = KillProcessByName (NOM_PROCESS)
 
'Ensuite tu fais ce que tu veux de retour, par exemple tu peux l'afficher dans une msgbox
msgbox retour