Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2005-05-11
5
Medium Priority
?
437 Views
Last Modified: 2010-03-18
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


0
Comment
Question by:it_stops
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:sweatbeast
ID: 13982375
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 http://www.microsoft.com/technet/prodtechnol/windowsserver2003/library/ServerHelp/22cf660f-c165-49e3-b768-2b8898a5684b.mspx
0
 
LVL 1

Author Comment

by:it_stops
ID: 13989924
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.
0
 
LVL 7

Expert Comment

by:sweatbeast
ID: 13991382
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 (WWW.sysinternals.com) should assist with this
0
 
LVL 7

Accepted Solution

by:
sweatbeast earned 1000 total points
ID: 13991389
also, have you tried copying the file to another location via the script? could be a problem at the source end
0
 
LVL 1

Author Comment

by:it_stops
ID: 14079805
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).
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is in response to a question (http://www.experts-exchange.com/Networking/Network_Management/Network_Analysis/Q_28230497.html) here at Experts Exchange. The Original Poster (OP) requires a utility that will accept a list of IP addresses …
A common practice in small networks is making file sharing easy which works extremely well when intra-network security is not an issue. In essence, everyone, that is "Everyone", is given access to all of the shared files - often the entire C: drive …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question