Joe
Joe

Reputation: 409

XCOPY hosts file on vista from a batch file

I need a command to replace the hosts file on my machine. Seems pretty straight forward but I cannot get the command to work with xcopy. Any obvious flaws in the command?

luaexec -w -f "XCOPY" "%ScriptPath%/ModifiedHosts/vista/hosts" "%windir%/system32/drivers/etc/hosts" /H

The /R flag does not seem to help and the error I get is "Error: ShellExecuteEx failed 0x2" if I remove all quotes but the beginning and end quotes

Upvotes: 2

Views: 2245

Answers (3)

Oddthinking
Oddthinking

Reputation: 25272

On Vista, you need to run as Administrator to change the hosts file.

Reference

Upvotes: 0

FerranB
FerranB

Reputation: 36767

Did you get any error?

Try this:

luaexec -w -f "XCOPY %ScriptPath%/ModifiedHosts/vista/hosts %windir%/system32/drivers/etc/hosts" /H

Also, you can try robocopy.

Upvotes: 1

Scott Evernden
Scott Evernden

Reputation: 39930

is the hosts file write protected? it probably is.. add a /R to your commandline

Upvotes: 0

Related Questions