5

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

我想使用 VBScript。

4

2 回答 2

5

您可以使用它来找出进程所有者是谁,然后一旦有了,您就可以使用 Win32_Process 通过进程 ID 终止进程。

MSDN Win32_Process 类详细信息

MSDN 使用 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
于 2008-09-18T02:11:13.230 回答
2

从http://sysinternals.com/转到 pskill

命令行:pskill -u user_1 attachemate.exe

于 2008-09-16T20:01:21.397 回答