Question : Overwriting Hosts file in Vista

With Vista, I am receiving an Access Denied error message when I try to run a batch file that overwrites my hosts file.

Here's some background.  I use my computer at work and at home.  At work, I access the internal web server via a 192.168 IP address.  From home, I use the public IP address.  In my Favorites, I have a number of links to pages on the web site.  Rather than creating two sets of favorites, with different IP addresses, I edit the hosts file to change the IP address of office web server, using either the internal or external address as needed.  I have written a batch program to automate this.  I pass in a parameter, and then copy one of two files, hosts.home or hosts.work, overwriting the previous hosts file.  The batch file and the two template files are located in the drivers|etc folder.  

This method works fine in XP, but does not work in Vista.  I have checked that I am an Admistrator.  

c:\Windows\System32\drivers\etc>copy hosts.home hosts
Overwrite hosts? (Yes/No/All): y
Access is denied.
        0 file(s) copied.

Does anyone know a workaround or an equivilent way of changing the hosts file.

Thanks

Answer : Overwriting Hosts file in Vista

You never "run" as admin... you run in a lower context and get prompted to elevate. The problem here is that notepad doesn't request the access. You have to run notepad as an admin... right click and runas.
Random Solutions  
 
programming4us programming4us