杀进程源码

  /// <summary>
        /// 杀死该进程
        /// </summary>
        /// <param name="filePath"></param>
        public bool KillProcess(string filePath)
        {
            string filename = Path.GetFileName(filePath);
            List<string> allFile = new List<string>();
            Process[] allprocess = Process.GetProcesses();
            try
            {
                for (int i = 0; i < allprocess.Length; i++)
                {
                    string[] str = allprocess[i].MainWindowTitle.Split('-');
                    for (int j = 0; j < str.Length; j++)
                    {
                        if (str[j].Contains("[兼容模式]"))
                        {
                            str[j] = str[j].Remove(str[j].Length - 6).Trim();
                        }
                        if (filename == str[j].Trim())
                        {
                            allprocess[i].Kill();
                        }
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

你可能感兴趣的:(源码)