Link to home
Start Free TrialLog in
Avatar of id4382
id4382Flag for United States of America

asked on

Using Windows Batch File to replace Hosts file

Hello,

I currently have a logon script that is set to replace the local machine Hosts file with that of a modified hosts file.

The problem that I am running into is that the original hosts file on the local machine is read-only, so the file is not copied over. I figured that out after removing the read-only access and then running my script again.

I am looking for the code snippet to remove the "read-only" permission before the script attempts to copy the file.

Can anyone show what the line of code I need for this?
copy "\\server\share\Hosts\*.*" "%systemroot%\system32\drivers\etc\" /Y

Open in new window

Avatar of Qlemo
Qlemo
Flag of Germany image

You can use xcopy instead, with option /R:

xcopy /R /Y /D \\server\share\Hosts\*.*" "%systemroot%\system32\drivers\etc\"
Option /D can be omitted, it will copy only files newer than the destination.
Is there entries already in the hosts file apart from default entry?
SOLUTION
Avatar of Bartender_1
Bartender_1
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of id4382

ASKER

The commands given by Qlemo worked successfully.