using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
class Program
{
private const int TH32CS_SNAPPROCESS = 0x00000002;
private const uint WM_CLOSE = 0x0010;
[DllImport("kernel32.dll")]
private static extern IntPtr CreateToolhelp32Snapshot(int dwFlags, uint th32ProcessID);
[DllImport("kernel32.dll")]
private static extern bool Process32First(IntPtr hSnapshot, ref PROCESSENTRY32 lppe);
[DllImport("kernel32.dll")]
private static extern bool Process32Next(IntPtr hSnapshot, ref PROCESSENTRY32 lppe);
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
public struct PROCESSENTRY32
{
public uint dwSize;
public uint cntUsage;
public uint th32ProcessID;
public IntPtr th32DefaultHeapID;
public uint th32ModuleID;
public uint cntThreads;
public uint th32ParentProcessID;
public int pcPriClassBase;
public uint dwFlags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szExeFile;
}
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
static void ListRunningApplications(ListBox listBox)
{
Process currentProcess = Process.GetCurrentProcess();
PROCESSENTRY32 processEntry = new PROCESSENTRY32();
processEntry.dwSize = (uint)Marshal.SizeOf(typeof(PROCESSENTRY32));
IntPtr snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
Process32First(snapshot, ref processEntry);
do
{
Process process = Process.GetProcessById((int)processEntry.th32ProcessID);
if (process.Id != currentProcess.Id && !IsSystemProcess(process))
{
listBox.Items.Add(process.ProcessName);
}
}
while (Process32Next(snapshot, ref processEntry));
CloseHandle(snapshot);
}
static bool IsSystemProcess(Process process)
{
return process.ProcessName == "System" || process.ProcessName == "Idle" || process.ProcessName.StartsWith("smss");
}
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool CloseHandle(IntPtr hObject);
public class Form1 : Form
{
private ListBox listBox;
private Button closeButton;
public Form1()
{
listBox = new ListBox();
listBox.Dock = DockStyle.Fill;
closeButton = new Button();
closeButton.Text = "Seçili Uygulamaları Kapat";
closeButton.Dock = DockStyle.Bottom;
closeButton.Click += CloseButton_Click;
Controls.Add(listBox);
Controls.Add(closeButton);
ListRunningApplications(listBox);
}
private void CloseButton_Click(object sender, EventArgs e)
{
foreach (var selectedItem in listBox.SelectedItems)
{
foreach (var process in Process.GetProcessesByName(selectedItem.ToString()))
{
process.Kill();
}
}
}
}
}