How can I kill a process using VBScript run by a specific user

I have several users running attachemate on a Windows 2003 server. I want to kill attachemate.exe launched by user_1 without killing attachemate.exe launched by user_2.

I want to use VBScript.

+5
source share
2 answers

You can use this to find out who owns the process, and then, as soon as you have it, you can use Win32_Process to kill the process by process ID.

MSDN Class Information Win32_Process

MSDN Process Termination Using Win32_Process

, , . . , , , , , - .:)

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
+5

pskill http://sysinternals.com/

: pskill -u user_1 attachemate.exe

+2

All Articles