Come posso terminare un processo, utilizzando VBScript, avviato da un particolare utente
-
09-06-2019 - |
Domanda
Ho più utenti che eseguono attachemate su un server Windows 2003.Voglio uccidere attachemate.exe avviato da utente_1 senza uccidere attachemate.exe avviato da utente_2.
Voglio usare VBScript.
Soluzione
Potresti usarlo per scoprire chi è il proprietario del processo, quindi una volta ottenuto puoi utilizzare Win32_Process per terminare il processo tramite l'ID del processo.
Dettagli della classe MSDN Win32_Process
MSDN Termina un processo con Win32_Process
Esiste sicuramente un modo più pulito per farlo, ma ecco cosa mi è venuto in mente.NOTA:Ovviamente questo non riguarda più processi con lo stesso nome, ma immagino che tu possa risolvere quella parte con un array per contenerli o qualcosa del genere.:)
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
Altri suggerimenti
Sborsare per pskill da http://sysinternals.com/
Riga di comando:pskill -u utente_1 attachemate.exe