How can I kill a process, using VBScript, started

2019-04-29 20:59发布

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

I want to use VBScript.

2条回答
欢心
2楼-- · 2019-04-29 21:13

Shell out to pskill from http://sysinternals.com/

Commandline: pskill -u user_1 attachemate.exe

查看更多
成全新的幸福
3楼-- · 2019-04-29 21:15

You could use this to find out who the process owner is, then once you have that you can use Win32_Process to kill the process by the process ID.

MSDN Win32_Process class details

MSDN Terminating a process with Win32_Process

There is surely a cleaner way to do this, but here's what I came up with. NOTE: This doesn't deal with multiple processes of the same name of course, but I figure you can work that part out with an array to hold them or something like that. :)

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
查看更多
登录 后发表回答