Comment puis-je tuer un processus, en utilisant VBScript, lancé par un utilisateur particulier
-
09-06-2019 - |
Question
Plusieurs utilisateurs exécutent attachemate sur un serveur Windows 2003. Je veux tuer attachemate.exe démarré par user_1 sans tuer attachemate.exe démarré par user_2.
Je souhaite utiliser VBScript.
La solution
Vous pouvez utiliser ceci pour savoir qui est le propriétaire du processus, puis vous pouvez utiliser Win32_Process pour tuer le processus à l'aide de l'ID de processus.
Détails de la classe MSDN Win32_Process
MSDN Terminer un processus avec Win32_Process
Il existe sûrement une manière plus propre de procéder, mais voici ce que j’ai proposé. NOTE: Bien entendu, cela ne concerne pas plusieurs processus du même nom, mais je suppose que vous pouvez utiliser cette partie avec un tableau pour les contenir ou quelque chose du genre. :)
strComputer = "."
strOwner = "A111111"
strProcess = "'notepad.exe'"
' Connect to WMI service and Win32_Process filtering by name'
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcessbyName = objWMIService.ExecQuery("Select * from Win32_Process Where Name = " _
& strProcess)
' Get the process ID for the process started by the user in question'
For Each objProcess in colProcessbyName
colProperties = objProcess.GetOwner(strUsername,strUserDomain)
if strUsername = strOwner then
strProcessID = objProcess.ProcessId
end if
next
' We have the process ID for the app in question for the user, now we kill it'
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process where ProcessId =" & strProcessID)
For Each objProcess in colProcess
objProcess.Terminate()
Next
Autres conseils
Créez un shell pour pskill à partir de http://sysinternals.com/
.Ligne de commande: pskill -u user_1 attachemate.exe