zoukankan      html  css  js  c++  java
  • C#杀进程与之之子进程

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Management;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ProcessDog.Helper
    {
        public static class ProcessHelper
        {
            /// <summary>
            /// Kill a process, and all of its children, grandchildren, etc.
            /// </summary>
            /// <param name="pid">Process ID.</param>
            public static void KillProcessAndChildren(int pid)
            {
                // Cannot close 'system idle process'.
                if (pid == 0)
                {
                    return;
                }
                ManagementObjectSearcher searcher = new ManagementObjectSearcher
                        ("Select * From Win32_Process Where ParentProcessID=" + pid);
                ManagementObjectCollection moc = searcher.Get();
                foreach (ManagementObject mo in moc)
                {
                    KillProcessAndChildren(Convert.ToInt32(mo["ProcessID"]));
                }
                try
                {
                    Process proc = Process.GetProcessById(pid);
                    proc.Kill();
                }
                catch (ArgumentException)
                {
                    // Process already exited.
                }
            }
    
        }
    }
  • 相关阅读:
    js练习 导航栏下拉子菜单
    js练习 DIV做下拉列表
    js添加事件
    HTML5音频和视频
    HTML5表单元素拓展
    document对象
    DOM
    函数
    常用的函数及递归
    JavaScript数组示例
  • 原文地址:https://www.cnblogs.com/nocanstillbb/p/11428116.html
Copyright © 2011-2022 走看看