Bonjour à tous,
j'aimerais faire une comparaison de fichiers textes (liste de processus, avant et aprés) en VBS, afin d'en sortir les processus en trop , et de les arrêter :
liste 1 (avant) , file1.txt : aaa.exe , bbb.exe
liste 2 (après) , file2.txt : aaa.exe , bbb.exe , notepad.exe

newtab = compare (file1, file2) ;
foreach element in newtab {
killprocess (element);
}

=> notepad.exe est arrété.

je débute en VBS , j'ai besoin de votre aide

Voilà de mes 2 premiers scripts :
- le premier pour récupérer la première liste de process en cours
- le deuxieme pour tuer les process (pour l'instant je n'ai qu'une pauvre suite de "if strcompare" , c'est moche , je sais lol

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
 
Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strList, WshShell
 
 
  Const ForReading = 1, ForWriting = 2
  Set WshShell = WScript.CreateObject("WScript.Shell")
   Dim fso, f
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.OpenTextFile("c:\ecr.txt", ForWriting,true)
 
 
 
strComputer = "."
 
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _ 
& strComputer & "\root\cimv2") 
 
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process")
 
For Each objProcess in colProcess
strList = strList & vbCr & _
objProcess.Name
f.writeline (objProcess.Name)
 
Next
 
'if (strcomp 
 
WSCript.Echo strList
WScript.Quit
 
' End of List Process Example VBScript
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
' killProcess.vbs
' VBScript kill processes that were not running before , used to finish the app-v sequence
' Author me
' July 2011
' -------------------------------------------------------' 
Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strList, WshShell
 
strComputer = "."
 
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _ 
& strComputer & "\root\cimv2") 
 
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process")
 
For Each objProcess in colProcess
strList = strList & vbCr & _
objProcess.Name
'f.writeline (objProcess.Name)
 
if ( (strcomp (objProcess.Name , "System Idle Process") <> 0) And (strcomp (objProcess.Name , "System") <> 0)  And  (strcomp (objProcess.Name , "smss.exe") <> 0) And (strcomp (objProcess.Name , "csrss.exe") <> 0)   And (strcomp (objProcess.Name , "winlogon.exe") <> 0)   And (strcomp (objProcess.Name , "services.exe") <> 0)   And (strcomp (objProcess.Name , "lsass.exe") <> 0)   And (strcomp (objProcess.Name , "vmacthlp.exe") <> 0)   And (strcomp (objProcess.Name , "xtagent.exe") <> 0)   And (strcomp (objProcess.Name , "svchost.exe") <> 0)   And (strcomp (objProcess.Name , "spoolsv.exe") <> 0)   And (strcomp (objProcess.Name , "imapi.exe") <> 0)   And (strcomp (objProcess.Name , "MDM.EXE") <> 0)   And (strcomp (objProcess.Name , "ZenRem32.exe") <> 0)   And (strcomp (objProcess.Name , "UphClean.exe") <> 0)   And (strcomp (objProcess.Name , "VMwareService.exe") <> 0)   And (strcomp (objProcess.Name , "WM.EXE") <> 0)   And (strcomp (objProcess.Name , "alg.exe") <> 0)   And (strcomp (objProcess.Name , "WMRUNDLL.EXE") <> 0)   And (strcomp (objProcess.Name , "explorer.exe") <> 0)   And (strcomp (objProcess.Name , "dpmw32.exe") <> 0)   And (strcomp (objProcess.Name , "nwtray.exe") <> 0)   And (strcomp (objProcess.Name , "VMwareTray.exe") <> 0)  And (strcomp (objProcess.Name , "VMwareUser.exe") <> 0)  And (strcomp (objProcess.Name , "RemoteAdmin.exe") <> 0)  And (strcomp (objProcess.Name , "igfxsrvc.exe") <> 0)  And (strcomp (objProcess.Name , "dllhost.exe") <> 0)  And (strcomp (objProcess.Name , "msdtc.exe") <> 0)  And (strcomp (objProcess.Name , "sftvsa.exe") <> 0) And (strcomp (objProcess.Name , "wscript.exe") <> 0)  And (strcomp (objProcess.Name , "wmiprvse.exe") <> 0) And (strcomp (objProcess.Name , "SFTSequencer.com") <> 0) And (strcomp (objProcess.Name , "SFTSequencer.exe") <> 0)And (strcomp (objProcess.Name , "wmiprvse.exe") <> 0)) Then 
 
'process killed
'msgbox "killed process : " & objProcess.Name
objProcess.Terminate()
 
End If
Next
 
 
 
 
'WSCript.Echo strList
WScript.Quit
 
' End of List Process Example VBScript