C#: Programmatically “Run As Administrator”

A few days ago I wanted to write to hosts, a HOSTS file in system32 used by Microsoft TCP/IP for Windows. Since this file is protected, you can edit it in administrative mode only. This means the user has to right click it and select “Run as administrator” for your project to run correctly. Fortunately there is a solution. The following code will request admin access from the user, and rerun it’s self in admin mode:

Continue reading

Advertisements