Cybermonk
Cybermonk

Reputation: 524

Edit UAC Protected file in windows

How to edit and save uac protected files especially the hosts file (DNS mapping) through bat file / java.

Java throws IO exception. Because the file is not writable. Set write also fails.

   File file = new File("C:\\Windows\\System32\\drivers\\etc\\hosts");
   file.setWritable(true);
   FileUtils.writeStringToFile(file, "127.0.0.1 test.com", true);

Exception File 'C:\Windows\System32\drivers\etc\hosts' cannot be written to

Upvotes: 0

Views: 125

Answers (1)

janith1024
janith1024

Reputation: 1042

You have to give write permission default host file has read and execute permission only

enter image description here

Upvotes: 1

Related Questions