4 Temmuz 2016 Pazartesi

c# windows process

1). Create a new C# windows application in Visual Studio.
2). Drag from the ToolBox onto the window the following items:
a). 1 listbox
b). 2 buttons
c). 1 label
d). 1 timer
e). 1 label
3). Rename the following from their properties box:
listbox1—>listboxProcess
textBox1—>textBoxName
button1—>buttonBlock
button2—>buttonAllow
label1—>labelStatus
4). Also, make the value of HorizontalScrollBar in the properties of listbox as “true”.
5). Value of Enabled=true and Interval=100 for the timer in the properties box.
6). Give your form the following look:
7). Place the labelStatus below the buttons. This will tell us if the application is blocking a process or not.
8). Include the following line in the .cs file: “using System.Diagnostics;” This will not be automatically written by      Visual Studio.
9). Write the following lines of code in form’s load event, button click events, etc etc.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;//INCLUDED MANUALLY
namespace TaskMan
{
public partial class FormTaskMan : Form
{
string targetProcess;
public FormTaskMan()
{
InitializeComponent();
}
private void FormTaskMan_Load(object sender, EventArgs e)
{
//GETTING THE LIST OF PROCESSES
foreach (Process p in Process.GetProcesses())
{
listBoxProcess.Items.Add(p.ProcessName+”—–>”+p.MainWindowTitle
}
labelStatus.Text = “”;
}
private void buttonBlock_Click(object sender, EventArgs e)
{
targetProcess = textBoxName.Text;
labelStatus.Text = textBoxName.Text + ” BLOCKED!”;
}
private void buttonAllow_Click(object sender, EventArgs e)
{
targetProcess = “”;
labelStatus.Text =”ALLOWED!”;
}
private void timer1_Tick(object sender, EventArgs e)
{
foreach (Process p1 in Process.GetProcesses())
{
//targetProcess WILL BE BLOCKED, WINDOWS TASKMANAGER WILL BE BLOCKED, AND THE APPLICATION ITSELF CANNOT BE BLOCKED!
if ((p1.ProcessName==targetProcess) || p1.ProcessName.StartsWith(“taskmgr”) && p1.ProcessName.StartsWith(“TaskMan”)==false)
{
try
{
p1.Kill();
}
catch (Win32Exception)
{
//Process cannot be blocked😦
}
}
}
}
}
}
Enjoy…😛
Try it our with a few processes like “wmplayer” for Windows Media Player, “firefox” for Mozilla Firefox, “iexplore” for Internet Explorer…