Tuer un processus vbs

ayarikhaoula Messages postés 126 Date d'inscription vendredi 13 août 2010 Statut Membre Dernière intervention 15 août 2011 - 1 mars 2011 à 09:22
NHenry Messages postés 15113 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 22 avril 2024 - 1 mars 2011 à 12:51
salut tout le monde.je souhaite développé un script vbs qui tue un processus encour d'éxécution si son nom contient une chaine donné.voici mon script mon problème c'est qu'il génère une erreur:argument ou appel de procédure incorrecte "INSTR"
Set objWMI = GetObject("winmgmts:root\cimv2")
sQuery = "Select * from Win32_process"
For Each oproc In objWMI.execquery(sQuery)
Wscript.echo oproc.Name
'& " = " & oproc.ExecutablePath
dim p
pos = InStr(0, oproc.Name , "ma_chaine")
if p<> 0 then
oproc.Terminate()
end if
Next
Set objWMI = Nothing
merci pour vos aide.

1 réponse

NHenry Messages postés 15113 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 22 avril 2024 159
1 mars 2011 à 12:51
Bonjour,

Et si à la place de :
pos = InStr(0, oproc.Name , "ma_chaine")
if p<> 0 then
oproc.Terminate()
end if

( pos ou p ? )

Tu fais :
if oproc.Name Like "*\ma_chaine" then
oproc.Terminate()
end if

Mon site
0
Rejoignez-nous