I am writing a small WPF utility for managing entries in the hosts file for dev purposes. As you know, the hosts file is protected by newer operating systems (Win 7/2008 / Vista).
I added a manifest to my application to set requestExecutionLevel to "requireAdministrator", as described in detail here (using the "easy way" ") and in the corresponding question here .
Unfortunately, this did not work for me. When I launch the application, there is no prompt for promotion, and calling the File.AppendText file for the hosts file still throws a System.UnauthorizedAccessException: "Access to path" C: \ Windows \ System32 \ drivers \ etc \ hosts "is denied" .
HostsChanger.exe.manifest:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="HostsChanger" type="win32"/> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> <security> <requestedPrivileges> <requestedExecutionLevel level="requireAdministrator"/> </requestedPrivileges> </security> </trustInfo> </assembly>
Any ideas?
security c # wpf elevated-privileges hosts-file
bszom
source share