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 :

tuer un processus


Sujet :

VBScript

  1. #1
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut tuer un processus
    Bonjour, je voudrai faire un script vbs pour tuer plusieurs processus, pouriez vous me donner un exemple pour tuer un processus ?

  2. #2
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    Je t'ai passé un lien qui contient certainement un millier de scripts.
    Fouille le un peu !!!
    Personnellement je me fatigue très vite de répondre à des postes où j'ai l'impression que l'auteur n'a pas fait d'effort pour rechercher l'information.

    Etre débutant n'excuse pas tout, et ne permet pas d'abuser de la patience des autres !!!

    L'information se trouve ici :
    http://www.activexperts.com/activmon...ermProcess.htm
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  3. #3
    Membre averti
    Inscrit en
    Août 2007
    Messages
    302
    Détails du profil
    Informations personnelles :
    Âge : 57

    Informations forums :
    Inscription : Août 2007
    Messages : 302
    Points : 341
    Points
    341
    Par défaut
    Salut,

    va voir l'article "How Can I Terminate a Process with a Specific PID?" des scripting guys, ici :

    http://www.microsoft.com/technet/scr...4/hey0927.mspx

    A++
    Plus tu pédales moins vite, moins t'avances plus vite.

  4. #4
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    Merci beaucoup

    Donc c'est ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colProcessList = objWMIService.ExecQuery _
        ("Select * from Win32_Process Where Name = 'Notepad.exe'")
    For Each objProcess in colProcessList
        objProcess.Terminate()
    Next

  5. #5
    Membre averti
    Inscrit en
    Août 2007
    Messages
    302
    Détails du profil
    Informations personnelles :
    Âge : 57

    Informations forums :
    Inscription : Août 2007
    Messages : 302
    Points : 341
    Points
    341
    Par défaut
    Pour compléter voici un excellent lien vers un HTA créé par un Russe qui traite les kills de processus :

    http://www.script-coding.info/WMI_ProcMon.html

    Parlant couremment le russe (et le babelfishien ), j'ai traduit son code comme ca :

    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
     
    <head>
    <meta http-equiv="content-type" content="text/html; charset=windows-1251">
    <object ID="mysink" CLASSID="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223"></object>
    <hta:application id="hta" applicationname="KillProc"
    contextmenu="yes"
    innerborder="no"
    maximizebutton="yes"
    minimizebutton="yes"
    navigable="yes"
    scroll="no"
    scrollflat="yes"
    selection="no"
    showintaskbar="yes"
    singleinstance="no"
    sysmenu="yes"
    version="1.0"
    windowstate="normal"
    >
    <title>Monitor the new processes</title>
    <style>
    Body			{
    					background-color: buttonface;
    					font-family: Arial Narrow;
    					cursor: arrow;
         	 		}
    Table			{
    	 				font-size:13px;
    	 			}
    #ListView1		{
    					font-size: 11px;
    				}
    #scroll			{
    					width: 250;
    					overflow: hidden;
    				}
    </style>
    <script language="vbscript">
    Dim locator, service, procTemp, vTrigg
    vTrigg = 0
    procTemp = ""
    Sub Window_Onload
    	ListView1.font = "arial" 
    	ListView1.View = 3
    	ListView1.GridLines = True
    	ListView1.ColumnHeaders.Add , , "Name of the process", 100
    	ListView1.ColumnHeaders.Add , , "PID", 50
    	ListView1.ColumnHeaders.Add , , "Time of the creation", 110
    	ListView1.ColumnHeaders.Add , , "Priority", 70
    	ListView1.ColumnHeaders.Add , , "Way to the feasible file", 250
    	ListView1.ColumnHeaders.Add , , "Owner", 140
    	self.Focus()
    	self.MoveTo 65,30
    	self.ResizeTo 755,550
    End Sub
    Sub Connect(ht, lg, pswd)
    	On Error Resume Next
    	Set wshNet = CreateObject("WScript.Network")
    	Set locator = CreateObject ("WbemScripting.SWbemLocator")
      	If isLogin.checked Then
      		Set service = locator.ConnectServer(ht, "root\CIMV2", lg, pswd)
      		If Err.Number = 0 Then
    	  		Call Query(ht, wshNet.ComputerName)
    	  	Else
    	  		alert Err.Description
    	  	End If
    	Else
    	  	Set service = locator.ConnectServer(ht)
    	  	If Err.Number = 0 Then
    	  		Call Query(ht, wshNet.ComputerName)
    	  	Else
    	  		alert Err.Description
    	  	End If
    	End If
    	Set wshNet = Nothing
    End Sub
    Sub Query(remoteHost, localHost)
    	myQuery = "SELECT * FROM __InstanceCreationEvent  WITHIN 1 WHERE TargetInstance ISA 'Win32_Process'"
      	service.ExecNotificationQueryAsync mysink ,myQuery
      	If remoteHost = "" Then
      		strmess = localHost
        	Else
      		strmess = remoteHost
      	End If
      	message.innerHTML = "Connected to " & strmess
      	If document.all.isLogin.checked Then
      		document.all.host.disabled = "True"
      		document.all.isLogin.disabled = "True"
      		document.all.login.disabled = "True"
      		document.all.passwd.disabled = "True"
      	Else
      		document.all.isLogin.disabled = "True"
      		document.all.host.disabled = "True"
      	End If
    End Sub
    Sub AddItem(ProcName, ProcID, ProcTime, ProcPriority, ProcPath, ProcOwner)
    	Set itmx = ListView1.ListItems.Add(, , ProcName)
    	itmX.SubItems(1) = ProcID
    	itmX.SubItems(2) = ProcTime
    	itmX.SubItems(3) = ProcPriority
    	If IsNull(ProcPath) Then
    		itmX.SubItems(4) = ""
    	Else
    		itmX.SubItems(4) = ProcPath
     
    	End If
    	itmX.SubItems(5) = ProcOwner
    End Sub
    Sub ListView1_Click
    	On Error Resume Next
    	If ListView1.SelectedItem.Text <> "" Then
    		document.all.Kill.value = ListView1.SelectedItem.Text
    	End If
    End Sub
    Sub ListView1_ColumnClick(ColumnHeader)
    	With ListView1
    		.Sorted = False
    		.SortKey = ColumnHeader.Index - 1
    		If .SortOrder = 0 Then
    			.SortOrder = 1
    		Else
    			.SortOrder = 0
    		End If
    		.Sorted = True
    	End With
    End Sub
    Sub KillOne()
    	On Error Resume Next
    	If document.all.Kill.value <> "" Then
    		Set colProcessList = service.ExecQuery("Select * from Win32_Process Where Name = '" & document.all.Kill.value & "'")
    		For Each objProcess in colProcessList
    		    ret = objProcess.Terminate()
    		    If ret <> 0 Then
    		    	alert("It is not possible to complete process!")
    		    End If
    		Next
    		Set colProcessList = Nothing
    		document.all.Kill.value = ""
    		ListView1.ListItems.Remove(ListView1.SelectedItem.Index)
    	Else
    		alert("Process is not selected!")
    	End If
    End Sub
    Sub KillPermanent()
    	If document.all.Kill.value <> "" Then
    		ProcTemp = document.all.Kill.value
    	Else
    		alert("Process is not selected!")
    	End If
    End Sub
    Sub wbemsinkCancel()
    	mysink.cancel()
    	If document.all.isLogin.checked Then
      		document.all.host.disabled = "False"
      		document.all.isLogin.disabled = "False"
      		document.all.login.disabled = "False"
      		document.all.passwd.disabled = "False"
      	Else
      		document.all.isLogin.disabled = "False"
      		document.all.host.disabled = "False"
      	End If
    End Sub
    Sub ClearGrid()
    	ListView1.ListItems.Clear()
    End Sub
    Sub Window_OnUnload
    	mysink.cancel()
    	Set service = Nothing
    	Set locator = Nothing
    End Sub
    </script>
    <script language="vbscript" FOR="mysink" EVENT="OnProgress(iUpperBound, iCurrent, strMessage, objWbemAsyncContext)">
    	alert("Progress")
    </script>
    <script language="vbscript" FOR="mysink" EVENT="OnCompleted(iHResult, objWbemErrorObject, objWbemAsyncContext)">
    	document.all.Kill.value = ""
    	Call ClearGrid()
    	alert("Monitoring is opened.")
    	message.innerHTML = "Opened"
    </script>
    <script language="vbscript" FOR="mysink" EVENT="OnObjectReady(obj, objAsyncContext)">
    	timeCreated = obj.TargetInstance.CreationDate
    	TimeCreated = Mid(timeCreated, 1, 4) & "." & Mid(timeCreated, 5, 2) & "." & Mid(timeCreated, 7, 2) & "  " & Mid(timeCreated, 9, 2) & ":" & Mid(timeCreated, 11, 2) & ":" & Mid(timeCreated, 13, 2)
    	colProp = obj.TargetInstance.GetOwner(User,Domain)
    	Call AddItem(obj.TargetInstance.Name, obj.TargetInstance.ProcessID, timeCreated, obj.TargetInstance.Priority, obj.TargetInstance.ExecutablePath, Domain & "\" & User)
    	If obj.TargetInstance.Name = ProcTemp Then
    		obj.TargetInstance.Terminate()
    	End If
    </script>
    <script language="javascript">
    	var xInit;
    	xInit = 0;
    	function full()
     
    	{
    	if (document.all.isLogin.checked)
    	{
    		if (xInit < 720)
    		{
    			xInit += 40;
    			document.all.scroll.style.width = xInit;
    			var x = setTimeout("full()", 0.08);
    		}
    		else
    		{
    			clearTimeout(x);
    		}
    	}
    	else
    	{
    		document.all.scroll.style.width = 250;
    		xInit = 0;
    	}
    }
     
    </script>
    </head>
    <body>
    <table cellpadding="0" style="border-collapse: collapse" width="720" height="467">
    	<tr>
    		<td colspan="5">
    			<div id="scroll">
    				<table  border="0" cellpadding="0" style="border-collapse: collapse" width="730" height="100%">
    					<tr>
    						<td width="37">
    							Host:
    						</td>
    						<td  width="136">
    							<input name="host" type="text" style="width: 100; border: 1px solid black;">
    						</td>
    						<td   width="20">
    							<input name="isLogin" type="checkbox" onclick="full()" style="cursor: hand;" onmouseover='javascript: (this.checked)?this.title="Connection under the the alternative loginom with the remote system ": this.title="Soedinenie with that flowing loginom with any system"; '>
    						</td>
    						<td width="85">
    							Login:
    						</td>
    						<td width="31">
    							Name:
    						</td>
    						<td width="147">
    							&nbsp;<input name="login" type="text" style="width: 137; border: 1px solid black; height:19" name="T1" size="20"></td>
    						<td width="47">
    							Password:
    						</td>
    						<td width="231">
    							<input name="passwd" type="password" style="width: 137; border: 1px solid black; height:19" name="T2" size="20">
    						</td>
    					</tr>
    					<tr>
    						<td width="191" colspan="3">
    							<input type="button" style="cursor: hand; border: 1px solid black; height:19; font-size: 11px;  width:88" value="Connect" onclick="vbscript: call Connect(document.all.host.value, document.all.login.value, document.all.passwd.value)">
    						</td>
    						<td width="539" colspan="5">
    							<span lang="ru">&nbsp;</span></td>
    					</tr>
    					<tr>
    						<td width="191" colspan="3">
    							<input type="button" style="cursor: hand; border: 1px solid black; height:19; font-size: 11px; width:88" value="Open" onclick="wbemsinkCancel()"></td>
    						<td width="539" colspan="5">
    							&nbsp;</td>
    					</tr>
    				</table>
    			</div>
    		</td>
    	</tr>
    	<tr>
    		<td width="720" height="340" colspan="5" style="border: 1px solid #000000">
    									<OBJECT ID="ListView1" WIDTH=720 HEIGHT=340 CLASSID="CLSID:BDD1F04B-858B-11D1-B16A-00C0F0283628">
    									        <PARAM NAME="SortKey" VALUE="0">
    									        <PARAM NAME="View" VALUE="2">
    									        <PARAM NAME="Arrange" VALUE="0">
    									        <PARAM NAME="LabelEdit" VALUE="1">
    									        <PARAM NAME="SortOrder" VALUE="0">
    									        <PARAM NAME="Sorted" VALUE="-1">
    									        <PARAM NAME="MultiSelect" VALUE="0">
    									        <PARAM NAME="LabelWrap" VALUE="-1">
    									        <PARAM NAME="HideSelection" VALUE="0">
    									        <PARAM NAME="HideColumnHeaders" VALUE="0">
    									        <PARAM NAME="OLEDragMode" VALUE="0">
    									        <PARAM NAME="OLEDropMode" VALUE="0">
    									        <PARAM NAME="AllowReorder" VALUE="-1">
    									        <PARAM NAME="Checkboxes" VALUE="0">
    									        <PARAM NAME="FlatScrollBar" VALUE="0">
    									        <PARAM NAME="FullRowSelect" VALUE="-1">
    									        <PARAM NAME="GridLines" VALUE="-1">
    									        <PARAM NAME="HotTracking" VALUE="0">
    									        <PARAM NAME="HoverSelection" VALUE="0">
    									        <PARAM NAME="PictureAlignment" VALUE="0">
    									        <PARAM NAME="TextBackground" VALUE="0">
    									        <PARAM NAME="ForeColor" VALUE="-2147483640">
    									        <PARAM NAME="BackColor" VALUE="-2147483624">
    									        <PARAM NAME="BorderStyle" VALUE="0">
    									        <PARAM NAME="Appearance" VALUE="0">
    									        <PARAM NAME="MousePointer" VALUE="0">
    									        <PARAM NAME="Enabled" VALUE="1">
    									        <PARAM NAME="NumItems" VALUE="0"> 
    									   		<param name="OLEDragMode" value="0">
    											<param name="OLEDropMode" value="0">
    									   </OBJECT>
    		</td>
    	</tr>
    	<tr>
    		<td width="720" height="17" colspan="5">
    									</td>
    	</tr>
    	<tr>
    		<td width="233" height="18">
    			<input type="text" name="Kill" style="border: 0px; height:18; font-size: 11px;  width:233"
    									</td>
    		<td width="103" height="18">
    							<input type="button" style="cursor: hand; border: 1px solid black; height:19; font-size: 11px;  width:100" value="Kill" onclick="KillOne()"></td>
    		<td width="123" height="18">
    							<input type="button" style="cursor: hand; border: 1px solid black; height:19; font-size: 11px;  width:120" value="Kill all" onclick="KillPermanent()"></td>
    		<td width="131" height="18">
    									<input type="button" style="cursor: hand; border: 1px solid black; height:19; font-size: 11px;  width:120" value="Clean the grid" onclick="ClearGrid()"></td>
    		<td width="140" height="18">
    									</td>
    	</tr>
    	<tr>
    		<td width="720" height="23" colspan="5">
    									&nbsp;</td>
    	</tr>
    	<tr>
    		<td width="720" height="23" colspan="5" id="message">Opened
    									</td>
    	</tr>
    </table>
    </body>
    Sauvegardez ce code avec une extension .HTA
    Puis cliquez sur le bouton "Connect" pour se connecter en local ou entrez un nom de machine dans la zone host puis un compte d'admin avec mot de passe pour une machine distante puis cliquer sur "Connect" puis "Open".
    A partir de ce moment, la listview va monitorer tous les nouveaux process qui se lancent.
    Ouvrir par exemple un notepad et dans la listview, selectionner notepad.exe, puis cliquer sur le bouton "kill" pour tuer le process.

    Voilà du très beau boulot. Avec un peu de chance, il y a son nom là dedans "Автор статьи - Александр Нагаев, г. Москва" (Москва = Moscou).

    A++
    Plus tu pédales moins vite, moins t'avances plus vite.

  6. #6
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    Pas mal, mais il n'est pas robuste
    Après s'etre connecté et avoir cliqué sur open :
    ouvre notepad.
    sélectionne le sous le logiciel.
    Ferme le normalement sans kill.
    Refresh sur le logiciel. Normalement le nom reste dans la textebox.
    Ouvre autre chose.
    Dans le logiciel appuis sur kill sans faire de selection.
    Rien n'est killé mais un clear du contenu est effectué et tu ne vois plus ton processus

    Bon ok je fait n'importe quoi, mais j'ai beaucoup dev pour automatiser des plateformes de test

    Ha oui autre truc marrant, déplace un fichier notepad dans la fenetre du logiciel. Sympas aussi.
    Et en plus le processus notepad disparait.

    Comment faire disparaitre un process en laissant l'application lancé
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  7. #7
    Membre averti
    Inscrit en
    Août 2007
    Messages
    302
    Détails du profil
    Informations personnelles :
    Âge : 57

    Informations forums :
    Inscription : Août 2007
    Messages : 302
    Points : 341
    Points
    341
    Par défaut
    [QUOTE=ced600;2838560]Pas mal, mais il n'est pas robuste
    QUOTE]

    Ben d'un autre coté, c'est du Russe
    Plus tu pédales moins vite, moins t'avances plus vite.

  8. #8
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    Merci encore

    Mais je voulai juste tuer un processus

  9. #9
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    Ok nous on tue le temps
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  10. #10
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    pas de probléme, c'été juste pour que vous ne vous cassiez pas la tête pour rien que je disait ca


    Merci encore

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

Discussions similaires

  1. Comment tuer les processus dans l'état sleeping sans EM ?
    Par David Guillouet dans le forum MS SQL Server
    Réponses: 3
    Dernier message: 04/02/2005, 09h42
  2. Tuer un processus sur une machine distante
    Par nuke_y dans le forum Autres Logiciels
    Réponses: 2
    Dernier message: 16/11/2004, 09h55
  3. Comment tuer le processus ez-ipupdate
    Par berry dans le forum Applications et environnements graphiques
    Réponses: 4
    Dernier message: 21/06/2004, 15h07
  4. Tuer le processus d'Interbase ?
    Par JezabelleTwin dans le forum Bases de données
    Réponses: 4
    Dernier message: 07/04/2004, 13h09
  5. [VB6] [Système] Tuer un processus courant
    Par mdoyer dans le forum VB 6 et antérieur
    Réponses: 7
    Dernier message: 22/10/2002, 14h47

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