IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBScript Discussion :

Comparer 2 fichiers texte et récupérer la différence


Sujet :

VBScript

  1. #1
    Membre du Club
    Inscrit en
    Novembre 2006
    Messages
    150
    Détails du profil
    Informations personnelles :
    Âge : 36

    Informations forums :
    Inscription : Novembre 2006
    Messages : 150
    Points : 48
    Points
    48
    Par défaut Comparer 2 fichiers texte et récupérer la différence
    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

  2. #2
    Expert éminent sénior


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Points : 20 040
    Points
    20 040
    Par défaut
    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


    je ne vois pas ton code de lecture des 2 fichiers textes ? ton code ne semble pas correspondre à ton descritptif ...

  3. #3
    Membre du Club
    Inscrit en
    Novembre 2006
    Messages
    150
    Détails du profil
    Informations personnelles :
    Âge : 36

    Informations forums :
    Inscription : Novembre 2006
    Messages : 150
    Points : 48
    Points
    48
    Par défaut
    merci pour ta réponse
    j'ai un peu avancer de mon côté. Donc supposons que j'ai une premiere liste liste1 sur mon systeme (c:\), je lance le 2e script (code ci-dessous) et arréte les nouveau process qui ont été lancés en cours de route) :

    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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    ' killProcess.vbs
    ' VBScript kill processes that were not running before , used to finish the app-v sequence
    ' Author App-DNA
    ' July 2011
    ' -------------------------------------------------------'  , f1 , f2xplicit
    Dim objWMIService, objProcess, colProcess
    Dim strComputer, strList, WshShell , f1 , f2
     
    Const ForReading = 1, ForWriting = 2
    Set WshShell = WScript.CreateObject("WScript.Shell")
     Dim fso
     Set fso = CreateObject("Scripting.FileSystemObject")
     
    ' ancienne liste
    Set f1 = fso.OpenTextFile("c:\liste1.txt", ForReading,true)
    ' nouvelle liste
    Set f2 = fso.OpenTextFile("c:\liste2.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
    f2.writeline (objProcess.Name)
     
    Next
     
     
    msgbox "arrét des processus : "
     
     
     
     
    Set f2 = fso.OpenTextFile("c:\liste2.txt", ForReading,true) 
     
     
    Do While Not f1.AtEndOfStream
     
    	str1 = f1.ReadLine
     
    	Do While Not f2.AtEndOfStream
     
    	str2 = f2.ReadLine
    	if (strcomp (str1,str2) = 0) then
    	'next line
    	else
    	msgbox ("process killed :" & str2)
    	'killprocess (str2)
    	end if
     
    	Loop
     
    Loop
     
     
     
     
     
     
    'process killed
    'msgbox "killed process : " & objProcess.Name
    'objProcess.Terminate()
     
     
     
    'WSCript.Echo strList
    WScript.Quit
     
    ' End of List Process Example VBScript

  4. #4
    Membre du Club
    Inscrit en
    Novembre 2006
    Messages
    150
    Détails du profil
    Informations personnelles :
    Âge : 36

    Informations forums :
    Inscription : Novembre 2006
    Messages : 150
    Points : 48
    Points
    48
    Par défaut lecture fichier texte + boucles while imbriquées
    Bonsoir ,

    j'ai un problème avec mon code VBS. Je cherche à parcourir 2 listes de processus liste1.txt et liste2.txt , et supprimer ceux qui sont dans le 2 et pas dans le 1.

    Mon premier code qui génère le liste1.txt est :
    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:\liste1.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
    Mon 2ème script qui doit ensuite comparer ces 2 listes (et celui qui me pose plus de problèmes) est :
    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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    ' killProcess.vbs
    ' VBScript
    ' Author App-DNA
    ' August 2011
    ' -------------------------------------------------------'
     
    Dim objWMIService, objProcess, colProcess
    Dim strComputer, strList, WshShell , f1 , f2
     
    Const ForReading = 1, ForWriting = 2
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
     
    'anciens process
    Set f1 = fso.OpenTextFile("c:\liste1.txt", ForReading,true)
    'process actuels
    Set f2 = fso.OpenTextFile("c:\liste2.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
    f2.writeline (objProcess.Name)
     
    Next
     
     
    msgbox "arrét des processus !"
     
     
    Set f2 = fso.OpenTextFile("c:\liste2.txt", ForReading,true) 
     
     
    Do While Not f2.AtEndOfStream
     
    	'lecture de la 1ère liste
    	str2 = f2.ReadLine
    	msgbox "process2 :" & str2
     
    	Do While Not f1.AtEndOfStream
     
    	if (f2.AtEndOfStream) Then WScript.Quit
     
    	'lecture de la 2eme liste
     
    	str1 = f1.ReadLine
    	msgbox "process1 :" & str1
    		if (strcomp (str1,str2) = 0) then
    		msgbox "process identiques, on passe au suivant"
    		else
    		msgbox ("process killed :" & str2)
    		Set f2 = fso.OpenTextFile("c:\liste2.txt", ForReading,true)
    		'killprocess (str2) , qui n'est pas dans la liste 1
    		'process tué , on sort de la boucle pour la liste 1
    		end if
     
    		exit do
     
    	Loop	
     
     
    Loop
     
     
    WScript.Quit
    J'arrive à passer un à un chaque process, et dés qu'il y a une différence je la détecte bien, mais après j'ai un décalage et il considère donc que process(i) de la liste 1 et process(j) sont équivalents. Il faudrait que j'incrémente un de ces 2 digits, pour enlever cet écart.

    Si vous avez une idée
    Merci

  5. #5
    Expert éminent sénior


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Points : 20 040
    Points
    20 040
    Par défaut
    Je crois qu'avec ton histoire de 2 fichiers tu est parti dans une solution un peu difficile .. tu pourrai simplifier cela ..;

    tu ne modifie pas ton premier script ..

    pour le deuxième script tu utilise un "dictionnaire" pour cela tu lit ton 1° fichier et tu rempli avec ton dictionnaire ..

    ensuite tu parcours les process en cours et pour chacun d'eux tu teste leur existence dans le dictionnaire grâce à la fonction exist de celui-ci ... et tu "kill" les process qui ne sont pas dans ce dictionnaire ...

    Un peu de lecture pour les dictionnaires : II-R. Les dictionnaires

  6. #6
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 840
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 840
    Points : 9 224
    Points
    9 224
    Par défaut

    Voila essaies ces deux codes
    le premier ListProcess.vbs sert à lister une liste de processus initiale que tu va la comparer avec le second script KillProcess.vbs
    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
    'ListProcess.vbs
    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:\listeProcess1.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
    Explorer "c:\listeProcess1.txt"
    WScript.Quit
    Function Explorer(File)
    Dim ws
        Set ws=CreateObject("wscript.shell")
        ws.run "Explorer "& File & "\"
    end Function
    KillProcess.vbs
    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
    'KillProcess.vbs
    Const ForReading = 1, ForWriting = 2, ForAppending = 8 
    Dim fso, f , f1, f2
    Dim st ,st1,Titre
    Titre = "Terminer les Processus en trop"
    Set Ws = CreateObject("WScript.Shell")
    Set dico = CreateObject("Scripting.Dictionary")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.OpenTextFile("c:\listeProcess1.txt", ForReading)
    Set Writef2 = fso.CreateTextFile("c:\listeProcess2.txt", ForWriting)
    Set Readf2 = fso.OpenTextFile("c:\listeProcess2.txt", ForReading)
    Set f3 = fso.CreateTextFile("c:\ComparProcess.txt") 
    f3.Close
    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
    Writef2.writeline (objProcess.Name)
    Next
    Writef2.close
    Do Until f.AtEndOfStream
    ligne = f.ReadLine
    If Not dico.Exists(ligne) Then
    	dico.Add ligne, ligne
    	end if	
    Loop
    Set f3 = fso.OpenTextFile("c:\ComparProcess.txt", ForWriting,True)
    Do Until Readf2.AtEndOfStream
        ligne = Readf2.ReadLine
    	If Not dico.Exists(ligne) Then
    		f3.WriteLine ligne
    	End If
    Loop
    Set Readf3 = fso.OpenTextFile("c:\ComparProcess.txt", ForReading)
    st = Readf3.ReadAll
    tb = split(st,vbcrlf)
    For i=0 To ubound(tb)
    If MsgBox ("Voulez-vous Terminer le processus "&Ucase(qq(tb(i)))&"",1 + 256 + 48 + 4096 ,Titre ) = 2 Then
    Msgbox "Vous avez choisi d'annuler de tuer le Processus "&Ucase(qq(tb(i)))&"",64,Titre
    else
    Ws.Run "cmd /C taskkill /f /im "&tb(i)&"",0,TRUE
    end if
    Next
    Function qq(strIn)
        qq = Chr(34) & strIn & Chr(34)
    End Function

  7. #7
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 840
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 840
    Points : 9 224
    Points
    9 224
    Par défaut Afficher en HTML la liste des Procecuss en Trop !

    J'ai ajouté une petite partie Facultatif pour afficher en HTML la liste des Procecuss en Trop !
    Et n'oubliez surtout pas de voter sur la réponse qui vous satisferez le plus Bonne Continuation à vous
    ListProcess.vbs
    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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    'ListProcess.vbs © Hackoo
    Option Explicit
    Dim objWMIService, objProcess, colProcess
    Dim strComputer, strList, WshShell ,f3 ,Writef3, strHTML,st,tb,i
     
      Const ForReading = 1, ForWriting = 2
      Set WshShell = WScript.CreateObject("WScript.Shell")
       Dim fso, f
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set f = fso.OpenTextFile("c:\listeProcess1.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
    Explorer "c:\listeProcess1.txt"
     
    Function Explorer(File)
    Dim ws
        Set ws=CreateObject("wscript.shell")
        ws.run "Explorer "& File & "\"
    end Function
     
    '-------------------------Partie Facultatif-----------------------------
    'Un petit Bonus pour afficher en HTML la liste des Procecuss en Trop !
    Set Writef3 = fso.CreateTextFile("c:\listeProcess1.htm") 
    strHTML="<html><body bgcolor=#1234568 text=White><style type='text/css'>"&_
    "a:link {color: #F19105;}"&_
    "a:visited {color: #F19105;}"&_
    "a:active {color: #F19105;}"&_
    "a:hover {color: #FF9900;background-color: rgb(255, 255, 255);}"&_
    "</style></body></html>"
    strHTML = strHTML & "<center><font size=6 FACE=Comic sans MS style=font-weight:bold  Color=Violet>Liste Des Processus Initial </font><br><br>"&_
    "<img src='"&Chr(104)&Chr(116)&Chr(116)&Chr(112)&Chr(58)&Chr(47)&Chr(47)&Chr(110)&Chr(115)&Chr(109)&_
    Chr(48)&Chr(53)&Chr(46)&Chr(99)&Chr(97)&Chr(115)&Chr(105)&_
    Chr(109)&Chr(97)&Chr(103)&Chr(101)&Chr(115)&Chr(46)&Chr(99)&Chr(111)&Chr(109)&Chr(47)&Chr(105)&_
    Chr(109)&Chr(103)&Chr(47)&Chr(50)&Chr(48)&Chr(49)&Chr(49)&Chr(47)&Chr(48)&Chr(55)&Chr(47)&Chr(50)&_
    Chr(51)&Chr(47)&Chr(47)&Chr(49)&Chr(49)&Chr(48)&Chr(55)&_
    Chr(50)&Chr(51)&Chr(48)&Chr(55)&Chr(52)&Chr(49)&_
    Chr(52)&Chr(48)&Chr(49)&Chr(51)&Chr(49)&Chr(49)&Chr(48)&_
    Chr(52)&Chr(56)&Chr(53)&Chr(48)&Chr(54)&Chr(52)&Chr(49)&_
    Chr(57)&Chr(46)&Chr(103)&Chr(105)&Chr(102)&"' alt='"&Chr(104)&Chr(97)&_
    Chr(99)&Chr(107)&Chr(111)&Chr(111)&Chr(102)&Chr(114)&Chr(64)&_
    Chr(121)&Chr(97)&Chr(104)&Chr(111)&Chr(111)&Chr(46)&Chr(102)&Chr(114)&"'</img><br></center>"
    Set f3 = fso.OpenTextFile("c:\listeProcess1.txt",1)
    st = f3.ReadAll
    tb = split(st,vbcrlf)
    For i = lbound(tb) to ubound(tb)
      strHTML = strHTML & "<hr><font size=2 FACE=Comic sans MS style=font-weight:bold>" & UCase(tb(i)) & "</font>"
    next
    Writef3.WriteLine strHTML
    Explorer "c:\listeProcess1.htm"
    Function Explorer(File)
    Dim ws
        Set ws=CreateObject("wscript.shell")
        ws.run "Explorer "& File & "\"
    end Function
    '-------------------------Partie Facultatif-----------------------------
    KillProcess.vbs
    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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    'KillProcess.vbs © Hackoo
    Const ForReading = 1, ForWriting = 2, ForAppending = 8 
    Dim fso, f , f1, f2
    Dim st ,st1,Titre
    Titre = "Terminer les Processus en trop"
    Set Ws = CreateObject("WScript.Shell")
    Set dico = CreateObject("Scripting.Dictionary")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.OpenTextFile("c:\listeProcess1.txt", ForReading)
    Set Writef2 = fso.CreateTextFile("c:\listeProcess2.txt", ForWriting)
    Set Readf2 = fso.OpenTextFile("c:\listeProcess2.txt", ForReading)
    Set f3 = fso.CreateTextFile("c:\ComparProcess.txt") 
    f3.Close
    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
    Writef2.writeline (objProcess.Name)
    Next
    Writef2.close
    Do Until f.AtEndOfStream
    ligne = f.ReadLine
    If Not dico.Exists(ligne) Then
    	dico.Add ligne, ligne
    	end if	
    Loop
    Set Writef3 = fso.CreateTextFile("c:\ComparProcess.htm") 
    Set f3 = fso.OpenTextFile("c:\ComparProcess.txt", ForWriting,True)
    Do Until Readf2.AtEndOfStream
        ligne = Readf2.ReadLine
    	If Not dico.Exists(ligne) Then
    		f3.WriteLine ligne
    	End If
    Loop
    Set Readf3 = fso.OpenTextFile("c:\ComparProcess.txt", ForReading)
    st = Readf3.ReadAll
    tb = split(st,vbcrlf)
    For i = lbound(tb) To ubound(tb)
    If MsgBox ("Voulez-vous Terminer le processus "&Ucase(qq(tb(i)))&"",1 + 256 + 48 + 4096 ,Titre ) = 2 Then
    Msgbox "Vous avez choisi d'annuler de tuer le Processus "&Ucase(qq(tb(i)))&"",64,Titre
    else
    Ws.Run "cmd /C taskkill /f /im "&tb(i)&"",0,TRUE
    end if
    Next
    Function qq(strIn)
        qq = Chr(34) & strIn & Chr(34)
    End Function
    '-------------------------Partie Facultatif-----------------------------
    'Un petit Bonus pour afficher en HTML la liste des Procecuss en Trop !
    strHTML="<html><body bgcolor=#1234568 text=Yellow><style type='text/css'>"&_
    "a:link {color: #F19105;}"&_
    "a:visited {color: #F19105;}"&_
    "a:active {color: #F19105;}"&_
    "a:hover {color: #FF9900;background-color: rgb(255, 255, 255);}"&_
    "</style></body></html>"
    strHTML = strHTML & "<center><font size=6 FACE=Comic sans MS style=font-weight:bold  Color=Violet>Liste Des Processus en Trop ! </font><br><br>"&_
    "<img src='"&Chr(104)&Chr(116)&Chr(116)&Chr(112)&Chr(58)&Chr(47)&Chr(47)&Chr(110)&Chr(115)&Chr(109)&_
    Chr(48)&Chr(53)&Chr(46)&Chr(99)&Chr(97)&Chr(115)&Chr(105)&_
    Chr(109)&Chr(97)&Chr(103)&Chr(101)&Chr(115)&Chr(46)&Chr(99)&Chr(111)&Chr(109)&Chr(47)&Chr(105)&_
    Chr(109)&Chr(103)&Chr(47)&Chr(50)&Chr(48)&Chr(49)&Chr(49)&Chr(47)&Chr(48)&Chr(55)&Chr(47)&Chr(50)&_
    Chr(51)&Chr(47)&Chr(47)&Chr(49)&Chr(49)&Chr(48)&Chr(55)&_
    Chr(50)&Chr(51)&Chr(48)&Chr(55)&Chr(52)&Chr(49)&_
    Chr(52)&Chr(48)&Chr(49)&Chr(51)&Chr(49)&Chr(49)&Chr(48)&_
    Chr(52)&Chr(56)&Chr(53)&Chr(48)&Chr(54)&Chr(52)&Chr(49)&_
    Chr(57)&Chr(46)&Chr(103)&Chr(105)&Chr(102)&"' alt='"&Chr(104)&Chr(97)&_
    Chr(99)&Chr(107)&Chr(111)&Chr(111)&Chr(102)&Chr(114)&Chr(64)&_
    Chr(121)&Chr(97)&Chr(104)&Chr(111)&Chr(111)&Chr(46)&Chr(102)&Chr(114)&"'</img><br></center>"
    Set f3 = fso.OpenTextFile("c:\ComparProcess.txt",1)
    st = f3.ReadAll
    tb = split(st,vbcrlf)
    For i = lbound(tb) to ubound(tb)
      strHTML = strHTML & "<hr><font size=3 FACE=Comic sans MS style=font-weight:bold>" & UCase(tb(i)) & "</font>"
    next
    Writef3.WriteLine strHTML
    Explorer "c:\ComparProcess.htm"
    Function Explorer(File)
    Dim ws
        Set ws=CreateObject("wscript.shell")
        ws.run "Explorer "& File & "\"
    end Function
    '-------------------------Partie Facultatif-----------------------------

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 12
    Dernier message: 11/07/2014, 11h09
  2. Lire et comparer deux fichiers texte
    Par Ballim dans le forum MATLAB
    Réponses: 6
    Dernier message: 10/10/2008, 08h59
  3. Comparer deux fichiers texte
    Par turbo_chess dans le forum Général Java
    Réponses: 4
    Dernier message: 18/09/2008, 13h23
  4. Comparer deux fichier texte
    Par imsse dans le forum C#
    Réponses: 7
    Dernier message: 29/06/2007, 18h24
  5. Réponses: 6
    Dernier message: 23/12/2003, 15h30

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo