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.
我有多个用户在Windows 2003服务器上运行attachemate。我想杀死user_1启动的attachemate.exe而不杀死user_2启动的attachemate.exe。
I want to use VBScript.
我想使用VBScript。
2 个解决方案
#1
5
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.
您可以使用它来找出进程所有者是谁,然后一旦有了,您可以使用Win32_Process通过进程ID终止进程。
MSDN Win32_Process class details
MSDN Win32_Process类详细信息
MSDN Terminating a process with Win32_Process
MSDN使用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
#2
2
Shell out to pskill from http://sysinternals.com/
从http://sysinternals.com/打开外壳到pskill
Commandline: pskill -u user_1 attachemate.exe
命令行:pskill -u user_1 attachemate.exe
#1
5
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.
您可以使用它来找出进程所有者是谁,然后一旦有了,您可以使用Win32_Process通过进程ID终止进程。
MSDN Win32_Process class details
MSDN Win32_Process类详细信息
MSDN Terminating a process with Win32_Process
MSDN使用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
#2
2
Shell out to pskill from http://sysinternals.com/
从http://sysinternals.com/打开外壳到pskill
Commandline: pskill -u user_1 attachemate.exe
命令行:pskill -u user_1 attachemate.exe