Bonjour
Peut-on savoir si une application est en cours d'exécution?
Bonjour
Peut-on savoir si une application est en cours d'exécution?
Voici un exemple :
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 Titre = " Processus "& qq("Wscript.exe") &" en cours d'exécution " Set fso = CreateObject("Scripting.FileSystemObject") Set sho = CreateObject( "Wscript.Shell" ) NomFichierLog="Processus VBScript.txt" temp = sho.ExpandEnvironmentStrings("%temp%") PathNomFichierLog = temp & "\" & NomFichierLog Set OutPut = fso.CreateTextFile(temp & "\" & NomFichierLog,1) count=0 strComputer = "." Call FindAndKillScript() Call Explorer(PathNomFichierLog) '*************************************************************************************************** Function Explorer(File) Set ws=CreateObject("wscript.shell") ws.run "Explorer "& File & "\",1,True end Function '*************************************************************************************************** Sub FindAndKillScript() Set colItems = GetObject("winmgmts:").ExecQuery("Select * from Win32_Process " _ & "Where Name like '%wscript.exe%' AND NOT commandline like '%" & wsh.scriptname & "%'",,48) For Each objItem in colItems MsgBox "Arrêter ce script : " & objItem.CommandLine,48,Titre count= count + 1 'msgbox Mid(objItem.CommandLine,InStr(objItem.CommandLine,""" """) + 2),64,Titre OutPut.WriteLine Mid(objItem.CommandLine,InStr(objItem.CommandLine,""" """) + 2) objItem.Terminate(0) Next OutPut.WriteLine OutPut.WriteLine count & Titre & "ont été arrêtés" End Sub '*************************************************************************************************** Function qq(strIn) qq = Chr(34) & strIn & Chr(34) End Function '***************************************************************************************************
En supposant qu'il s'agit d'un "HTA" ou d'un "VBS", exécuté depuis une fenêtre Explorer.
Testez ce script
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 Titre = " Processus "& qq("Wscript.exe") &" en cours d'exécution " Set fso = CreateObject("Scripting.FileSystemObject") Set sho = CreateObject( "Wscript.Shell" ) NomFichierLog="Processus VBScript.txt" temp = sho.ExpandEnvironmentStrings("%temp%") PathNomFichierLog = temp & "\" & NomFichierLog Set OutPut = fso.CreateTextFile(temp & "\" & NomFichierLog,1) count=0 strComputer = "." Call Find("wscript.exe") Call Find("mshta.exe") Call Find("cmd.exe") Call Find("Firefox.exe") 'etc..... '........ '........ '........ Call Explorer(PathNomFichierLog) '*************************************************************************************************** Function Explorer(File) Set ws=CreateObject("wscript.shell") ws.run "Explorer "& File & "\",1,True end Function '*************************************************************************************************** Sub Find(MyProcess) Set colItems = GetObject("winmgmts:").ExecQuery("Select * from Win32_Process " _ & "Where Name like '%"& MyProcess &"%' AND NOT commandline like '%" & wsh.scriptname & "%'",,48) For Each objItem in colItems MsgBox "Arrêter ce script : " & objItem.CommandLine,48,Titre count= count + 1 'msgbox Mid(objItem.CommandLine,InStr(objItem.CommandLine,""" """) + 2),64,Titre OutPut.WriteLine Mid(objItem.CommandLine,InStr(objItem.CommandLine,""" """) + 2) objItem.Terminate(0) Next 'OutPut.WriteLine 'OutPut.WriteLine count & Titre & "ont été arrêtés" End Sub '*************************************************************************************************** Function qq(strIn) qq = Chr(34) & strIn & Chr(34) End Function '***************************************************************************************************
C'est bon, je vous remercie.
(un peu compliqué pour mon petit cerveau mais ça fonctionne)
Partager