@kevin david , Based on my research, you could change the hosts file
in the path C:\WINDOWS\system32\drivers\etc
to block user to access certain web pages.
You can add the following text to the end of the file.
For example:
127.0.0.1 www.google.com
Also, If you want to use the code to get it, here is a code example you could refer to.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string path = @"C:\WINDOWS\system32\drivers\etc\hosts";
List<string> list = new List<string>();
for (int i = 0; i < comboBox1.Items.Count; i++)
{
list.Add("127.0.0.1" + " " + comboBox1.Items[i].ToString());
}
File.AppendAllLines(path, list);
MessageBox.Show("The websites in the combobox has been blocked");
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("www.google.com");
comboBox1.Items.Add("stackoverflow.com");
}
private void button2_Click(object sender, EventArgs e)
{
string path = @"C:\WINDOWS\system32\drivers\etc\hosts";
string[] lines = File.ReadAllLines(path);
File.WriteAllLines(path, lines.Take(lines.Length - comboBox1.Items.Count).ToArray());
MessageBox.Show("The websites in the combobox has been blocked");
}
}
Note: Button1 is used to block websites and Button2 is used to unblock websites. We need to restart the browser to adapt the changes.
Tested result:
Hope this could help you.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.