【问题标题】:How can I kill a process, using VBScript, started by a particular user如何使用 VBScript 终止由特定用户启动的进程
【发布时间】:2010-09-09 17:30:10
【问题描述】:

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

我想使用 VBScript。

【问题讨论】:

    标签: vbscript windows-server-2003 kill


    【解决方案1】:

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

    MSDN Win32_Process class details

    MSDN Terminating a process with 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
    

    【讨论】:

      【解决方案2】:

      http://sysinternals.com/ 向 pskill 发送消息

      命令行:pskill -u user_1 attachemate.exe

      【讨论】:

      • 需要安装pskill并不理想。我更喜欢不需要我安装任何新东西的解决方案。
      猜你喜欢
      • 2010-10-27
      • 2018-09-30
      • 2014-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      相关资源
      最近更新 更多