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

我想使用 VBScript。

有帮助吗?

解决方案

您可以使用它来找出进程所有者是谁,然后一旦知道了,就可以使用 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

其他提示

shell 到 pskill from http://sysinternals.com/

命令行:pskill -u user_1 Attachemate.exe

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top