First you must learn the basics of C # and probably VisualStudio, you can not skip steps, this will only make the path harder. After learning about:
- Variables
- Functions
- Classes
- Object Orientation
- About method practices in csharp classes
- Compile a HelloWorld with Console and a Windows Form
So by doing this you can begin to study native (and non-native) libraries.
Once you have studied the basics, an example of killing an application that is what you want, to block you need kill
, you will need an "infinite" loop:
new Thread(() =>
{
while (true)
{
Thread.Sleep(100);
Process[] ps = Process.GetProcessesByName("NOME DO PROCESSO QUE DESEJA BLOQUEAR");
foreach (Process pr in ps)
{
pr.Kill();
pr.Close();
}
}
}).Start();
Note: Change "NOME DO PROCESSO QUE DESEJA BLOQUEAR"
to the name of the process you want to block.
With Process.GetProcessesByName
you can get the process by name, so with foreach
you can list all open instances and "kill" them, probably it should be inside an infinite loop in another Thread
.
As a console I think you will not need the Thread, unless you want to put Input commands, but perhaps it is just to block (I could not test):
using System;
public class BloquearProcessos
{
public static void Main()
{
while (true)
{
Thread.Sleep(100);
Process[] ps = Process.GetProcessesByName("NOME DO PROCESSO QUE DESEJA BLOQUEAR");
foreach (Process pr in ps)
{
pr.Kill();
pr.Close();
}
}
}
}
If it is a% w / o, the visual studio itself already creates a basic structure, but if you do not know where to apply the code follow an example:
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Thread eventThread = new Thread(() =>
{
while (true)
{
Thread.Sleep(100);
Process[] ps = Process.GetProcessesByName("NOME DO PROCESSO QUE DESEJA BLOQUEAR");
foreach (Process pr in ps)
{
pr.Kill();
pr.Close();
}
}
});
eventThread.IsBackground = true;
eventThread.Start();
}
}
}