Solved

C# Edit host file programmatically

Posted on 2013-01-11
4
3,400 Views
Last Modified: 2013-01-11
I am trying to edit the host file in Windows programaticly but keep failing.
Getting this error in VIsual Studio
{"Access to the path 'C:\\Windows\\system32\\drivers\\etc\\hosts' is denied."}

I google it and found this http://stackoverflow.com/a/10987320 but have no idea how to do that?.....I have never done that before, or if you guys have another solution?

Thanks
0
Comment
Question by:chugarah
  • 2
  • 2
4 Comments
 
LVL 2

Expert Comment

by:wvuser1
ID: 38767778
Basically what you need to do is run your programm as administrator:
http://stackoverflow.com/a/10767077/435878
0
 
LVL 1

Author Comment

by:chugarah
ID: 38767859
Nice fast answer. But I am not sure if that will solve my issue?

The program will autostart everytime the computer starts and sometimes users that doesnt have any admin rights will use it, is it possible to write the host file without UAC box?, this is supose to run in the background.
0
 
LVL 2

Accepted Solution

by:
wvuser1 earned 500 total points
ID: 38767897
Well then that sounds more like system service than a program.
http://stackoverflow.com/a/4640118/435878
0
 
LVL 1

Author Closing Comment

by:chugarah
ID: 38767940
Now we are talking :) Thanks, nice
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Connection String 16 60
Reset asp.net login password 4 42
Question! 4 36
Simple Injector with Web Service 4 41
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

777 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