[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C# Edit host file programmatically

Posted on 2013-01-11
4
Medium Priority
?
3,745 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

873 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