locked
[vb.net] Block a website by program

    Question

  • I wanna make a small program, which have a some list of website address to block. 

    I tried with adding those websites in "c:\windows\system32\drivers\etc\hosts" file. But not worked for me

    How can i achieve it by using vb.net? 


    Advance thanks!
    Tuesday, September 15, 2009 5:01 AM

Answers

  • Thanks for the reply,

    I tried already but doesnt work for me any other sugesstion!!!

    Hi aswinq,

        Welcomes to MSDN forums!
        I'm not sure what's going wrong, but this method works well on my computer, here are some suggestions you can refer to
        1. Cleare your browser's cache
        2. Make sure you disable DNS Client service via services.msc before you modify host file, flush your DNS cache using the following command 'ipconfig /flushdns'
        3. When you access internet, please don't use proxy.
        4. You'd better reboot your computer as well.

    Hope this helps

    Regards
    Jeff Shan
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Jeff Shan Tuesday, September 22, 2009 10:11 AM
    Monday, September 21, 2009 8:28 AM

All replies

  • Hello

    I think if you can try the following code

    private void button1_Click(object sender, EventArgs e)
            {
                String path = @"C:\Windows\System32\drivers\etc\hosts";
                StreamWriter sw = new StreamWriter(path, true);
                String sitetoblock = "\n 127.0.0.1 google.com";
                sw.Write(sitetoblock);
                sw.Close();
                MessageBox.Show("Site Blocked");
            }
        }

    This code should work
    • Proposed as answer by Amolpbhavsar Tuesday, September 15, 2009 2:11 PM
    Tuesday, September 15, 2009 2:11 PM
  • Thanks for the reply,

    I tried already but doesnt work for me any other sugesstion!!!
    Wednesday, September 16, 2009 3:55 PM
  • Hello

    I think if you can try the following code

    private void button1_Click(object sender, EventArgs e)
            {
                String path = @"C:\Windows\System32\drivers\etc\hosts";
                StreamWriter sw = new StreamWriter(path, true);
                String sitetoblock = "\n 127.0.0.1 google.com";
                sw.Write(sitetoblock);
                sw.Close();
                MessageBox.Show("Site Blocked");
            }
        }

    This code should work

    @ Amolpbhavsar : This vb.net forum, don't post C# code here

    kaymaf
    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Wednesday, September 16, 2009 6:54 PM
  • Thanks for the reply,

    I tried already but doesnt work for me any other sugesstion!!!

    Hi aswinq,

        Welcomes to MSDN forums!
        I'm not sure what's going wrong, but this method works well on my computer, here are some suggestions you can refer to
        1. Cleare your browser's cache
        2. Make sure you disable DNS Client service via services.msc before you modify host file, flush your DNS cache using the following command 'ipconfig /flushdns'
        3. When you access internet, please don't use proxy.
        4. You'd better reboot your computer as well.

    Hope this helps

    Regards
    Jeff Shan
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Jeff Shan Tuesday, September 22, 2009 10:11 AM
    Monday, September 21, 2009 8:28 AM