Un vbs fermant un processus

Résolu
cs_Kysic Messages postés 332 Date d'inscription mardi 12 juillet 2005 Statut Membre Dernière intervention 17 juillet 2010 - 27 juil. 2005 à 17:50
cs_Kysic Messages postés 332 Date d'inscription mardi 12 juillet 2005 Statut Membre Dernière intervention 17 juillet 2010 - 28 juil. 2005 à 11:30
Bonjour à tous.

Après avoir regardé les codes du sites, je n'ai pu trouver ce que je cherchais.

Il y a beaucoup de code expliquant comment fermer un processus, mais je
n'en est trouvé aucun sous forme de .vbs (je me sers déjà par
contre d'un fichier .vbs qui liste les processus).

Est-il possible ou non de fermer un processus à partir d'un fichier .vbs (en possédant déjà son id ou son nom) ?



Ps: je sens bien que quelqu'un à déjà du répondre à cette question, ou
que je l'ai mis dans le mauvais forum, j'ai pourtant chercher mais
comme j'y connaît vraiment rien toutes les commandes que j'ai pu essayé
on foiré.

Ps2: petite précision: je ne sais pas si c'est important mais j'utilise windows Me (bouh la honte !!!)

2 réponses

CTAC Messages postés 133 Date d'inscription mardi 24 décembre 2002 Statut Membre Dernière intervention 8 juin 2012 5
28 juil. 2005 à 00:01
Bonjour.

Ce code qui fonctionne sur Win98 utilise WMI pour lancer IE, récupérer son ProcessID puis fermer IE à l'aide du ProcessID.
Le chemin d'IE est codé en dur dans le script donc à adapter.

ctac

'ProcessWMI.vbs
Dim strComputer, objWMIService, objStartup, objConfig, _
objProcess, errReturn, strProcList, colProcesses
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
errReturn = objProcess.Create _
("C:\Program Files\Internet Explorer\IExplore.exe", _
Null, objConfig, intProcessID)
Wscript.Sleep 1000
If errReturn = 0 Then
MsgBox "Internet Explorer was started with a process ID of " _
& intProcessID & "." & vbNewLine & vbNewLine & _
"Internet Explorer va maintenant être fermé !", , _
"fermer un processus à partir d'un fichier .vbs"
Else
Wscript.Echo "Internet Explorer could not be started due to error " & _
errReturn & "."
End IfstrProcList "Select * from Win32_Process Where ProcessId " & _
SignedToUnSigned(intProcessID)
Set colProcesses = objWMIService.ExecQuery(strProcList)
For Each objProcess In colProcesses
objProcess.Terminate
Next
Wscript.Quit


Function SignedToUnSigned(SInt)
If SInt < 0 Then
SignedToUnSigned = CDbl(SInt Xor &H80000000) + _
&H7FFFFFFF + 1
Else
SignedToUnSigned = SInt
End If
End Function
3
cs_Kysic Messages postés 332 Date d'inscription mardi 12 juillet 2005 Statut Membre Dernière intervention 17 juillet 2010
28 juil. 2005 à 11:30
merci beaucoup, cela fonctionne, génial.
0
Rejoignez-nous