如何使用VBScript终止由特定用户启动的进程 [英] How can I kill a process, using VBScript, started by a particular user

查看:115
本文介绍了如何使用VBScript终止由特定用户启动的进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个用户在Windows 2003服务器上运行attachemate.我想杀死user_1启动的attachemate.exe,而不杀死user_2启动的attachemate.exe.

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.

我想使用VBScript.

I want to use VBScript.

推荐答案

您可以使用它来查找进程所有者是谁,然后一旦拥有,便可以使用Win32_Process通过进程ID终止该进程.

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类详细信息

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

这篇关于如何使用VBScript终止由特定用户启动的进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆