Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Startup script Access Denied when copying file

Status
Not open for further replies.

fh786

Technical User
Jul 8, 2008
32
GB
Hi,

Everytime this script runs I always get an access denied error message, this script is:

File1 = "File2.dll"
File2 = "File2.dat"
Const OverwriteExisting = True

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile File1, "C:\Destination\File1.dll", OverwriteExisting
objFSO.CopyFile File2, "C:\Destination\File2.dat", OverwriteExisting

set objFSO = Nothing

File2 copies across OK but gets an access denied message on File1, could it be because it is a DLL file?
 
I think I may know what the problem is, the files attribute is set to read only, is there a way I can uncheck read only and overwrite the file with the new one and then check the read only box?
 
Some sample code to show you how it is done.

Code:
'==========================================================================
'
' NAME: changeFileAttributes.vbs
'
' AUTHOR:  Mark D. MacLachlan, The Spider's Parlor 
' COPYRIGHT: (c) 2007 All Rights Reserved
' DATE  : 11/23/2007
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS 
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.
'
'
' COMMENT: <This script uses XOR to set bitmapped file attributes
' AND is first used to see if an attribute is Set
' then it is changed using XOR.>
'
'==========================================================================
Const Archive = 32
Const System = 4
Const Hidden = 2
Const ReadOnly = 1
Const NoAttribs = 0

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("C:\testfile.txt")
wscript.echo "Beginning attribute is " & objfile.attributes 
objFile.Attributes = Hidden + ReadOnly
WScript.Echo "End File Attribute is: " & objFile.Attributes

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thanks for the info; I have sroted the problem I just changed the script to delete the read only file and then copy the new version across with the other file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top