Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How to Add an entry to the host file from VB.Net

Posted on 2014-08-21
Medium Priority
Last Modified: 2014-08-24
I need to add an entry to the host file from a program that i am writing in VB.Net. I have tried to change the code in the following post but can’t get it to add rather than edit. http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_21862036.html Can someone please help me as I am running out of time to get the program finished.
All help will be greatly appreciated
Question by:JNeets
LVL 37

Accepted Solution

Kimputer earned 1200 total points
ID: 40278356
See output line, that's the most important one to watch (I just added something random):

        Dim Hosts As String = Environment.SystemDirectory & "\drivers\etc\hosts"
        Dim sr As New StreamReader(Hosts)
        Dim input As String = sr.ReadToEnd()
        Dim output As String = input + vbNewLine + " router"
        Dim sw As New StreamWriter(Hosts)

Open in new window

LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 800 total points
ID: 40278972
If it's not obvious, since the hosts file is in a protected system directory, any application that modifies it will need to be running with administrator privileges.

Author Closing Comment

ID: 40282052
Thanks Kimputer for the code I tryed it out and it worked purfectly. also thanks Kaufmed for the reminder that the program will have to run with administrator privileges.

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question