Access denied trying to copy hosts file to local using logon vbscript.

I wish to use a logon script to replace local hosts file with a customized one. i'm new to vbscripting. It works using excel file but doesn't like hosts or host.txt. it will copy host.txt by using *.txt in the script. I'm guessing it has something to do with the fact that it is in system32 child folder. Here is the sample of my script:

Set objFso = CreateObject("Scripting.FileSystemObject")

objFso.CopyFile "\\homer\everyone\hosts", "c:\windows\SYSTEM32\DRIVERS\etc"

Set objFso = Nothing

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The script is running in the context of the user and the user does not have permissions to overwrite an existing file(but they will have rights to create a new file).
So either you need elevate the users permissions, amend the permissions on the file or copy the file via another method.
Are the pc's in a win2k/3 domain? If so you can use group policy to run scripts against the machine directly - see
it_stopsAuthor Commented:
I am in a 2k3 domain. I am a local admin on this machine. I am a domain admin on the domain. I was running the script against the machine. If i doubleclick the script while logged in, it refuses to write hosts or hosts.txt to c:\windows\SYSTEM32\DRIVERS\etc. I get a wsh error info windows stating: Line 3, Char 1, Error Permission denied. The 3 lines in my script above are all that are in it. Lines 1-5. If the filename "hosts" is replaced with test.xls or ANY other file. I goes off without a hitch. Copies the file into c:\windows\SYSTEM32\DRIVERS\etc. If the script runs during my logon phase, I don't get any obvious error. The hosts file just doesn't get copied. Once again, any other file that I've tested during the logon, will get copied.
As a test give everyone full control over the hosts file to rule out permissions

Also, I guess there is also a chance its in use at the time - not aware of anything which would create a persistant lock though... PSFile within PSTools ( should assist with this
also, have you tried copying the file to another location via the script? could be a problem at the source end

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
it_stopsAuthor Commented:
I changed the code to:

Set objFso = CreateObject("Scripting.FileSystemObject")

objFso.CopyFile "C:\Documents and Settings\sweaver\Desktop\HOSTS.txt", "c:\test"

Set objFso = Nothing

(just to keep everything local)

and i still get the same error. I've played around with using HOSTS or HOST.txt and get the same permission denied error. I change access to everyone(full control) on all files and directories involved and nothing seems to help. I'm getting bombarded with work so this issue is on the back burner. My workaround was to manually add this file to critical machines. I'm interested for my own personal knowledge. I know that scripting is an extremely powerful timesaver when fully understood(having problems with the latter).
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Networking

From novice to tech pro — start learning today.