Winfoms problem in Hosts file
I am writing a mini site blocker, the program has 2 functions to block the site and add the site that needs to be blocked, I made sure that when the program starts, it closes in the windows tray and is added to the system startup. but I can't figure out how to make my text file with a list of sites to block replaced with an orginal hosts file
5 Replies
From my understanding what u want to do is block it on the firewall not on the hosts file
and how do you propose to block access to the site?
you block the ip on the firewall
Access to the host file is only permitted as
Admin
, so make sure the application is run as administrator.
To add/delete (CRUD Operation) you need a bit of a parser, you can write it yourself with basic string operations.
To be sure your application is started as Admin
, just ad an app.manifest
and use <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
.
For debuging, your VS must be started as admin aswell.
However, manipulating the hosts
is dangerous, keep that in mind!and very easy to bypass
as opposed to firewall blocking