Windows 7 requires extra treatment. Administrative privileges are required. Either run Codeblock as Administrator then run the program or compile it, execute it first time (it won’t work this time), go to the location of the generated EXE file, run the EXE as the administrator. Better go with first option. This program was coded to work with CodeBlock. Download CodeBlock mingw-setup from here.
Here is the program.
Code:
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
char site[20],ch;
ifstream in;
ofstream out;
cout<<"Enter the Name of the Site to Block \n";
cin>>site;
out.open("C:/Windows/System32/drivers/etc/hosts",ios::app);
if(!out)
cout<<"Either File Not Found or Permission Denied, Run as Admin the EXE of the Program";
else
{
out<<"127.0.0.1"<<"\t"<<site;
cout<<site;
cout<<"is blocked";
}
out.close();
return 0;
}
If you did everything as told, your output will be.
see the site is blocked
To unblock site:
To unblock sites follow the manual way and open the hosts file in notepad and delete last lines
That 127.0.0.1 www.site.com and save.
You might cannot modify the hosts file because of windows file permission issue, then
Right click on hosts files > properties > security > and to change permissions click edit then select user and check full control box and save now again open the hosts file and modify.
Also Read : Block any Website on Computer using C Code
Hope you like the post, comment bellow for Query and Feedback :)
4 comments:
if we want to unblock this site so what to do is there any programming code for it please tell me
@asad refer this post http://www.mycfiles.com/2011/12/c-program-unblocks-website.html
Thanks
Thank you so much .
Post a Comment