How to Close Run Program in ADO.NET

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9. using System.Diagnostics;  
  10. public void KillProgram() //This Method Create  
  11.     {  
  12.         // i'm Close Google Chrom My Project Name ProccessKillWindowsForm Not Close This Application  
  13.         foreach(Process item in Process.GetProcesses(".")) //GetProcesses(".") This Method Local Pc Name "." Local System  
  14.             {  
  15.                 try {  
  16.                     if ((item.MainWindowTitle.Length > 0) && (!item.ProcessName.ToLower().Contains("ProccessKillWindowsform") & item.ProcessName.ToLower().Contains("chrome"))) {  
  17.                         item.Kill();  
  18.                     }  
  19.                 } catch (Exception) {  
  20.                     throw;  
  21.                 }  
  22.             }  
  23.     }  
  24.   
  25. //Button Click Close This Program  
  26.   
  27. private void button1_Click(object sender, EventArgs e) {  
  28.     KillProgram();  
  29. }