On windows machine(with Windows 7 running, x86-64) is it possible to open ‘etc/hosts’ file which is in system32/drivers/etc, modify it and save from ruby?
I get “not opened for writing(IOError)” error
The code is very simple
file = File.open("C:/Windows/System32/drivers/etc/hosts")
file << "new line"
Instead of trying to acquire privileges from code ( which maybe won’t be portable across different windows OS’es ), do like this:
By doing like this, all the programs you’re executing will have administrative privileges as well.
EDIT: This is your problem:
You have to open the file in write mode.