VBS Script Permission Denied - Copying file

Hello,

I have a VBS script where I am trying to copy another script to the computers local C:\temp directory, but I keep getting a permission denied error when I try to run the script. The C:\temp allows write access to the user and I can manually copy the script down to the client and it works fine. The script that is runs when the user logs on is on a server share called Scripts. The script that the first script tries to copy is also in the same share. Here is the code:

Set fso = CreateObject("Scripting.FileSystemObject")

NewFolder = "C:\Temp"

If FSO.FolderExists( NewFolder ) then
     fso.CopyFile "\\server\scripts\LanConnection.vbs", NewFolder
end if

'Re-Create or create the folder

If NOT FSO.FolderExists( NewFolder ) then
     FSO.CreateFolder NewFolder
     fso.CopyFile "\\server\scripts\LanConnection.vbs", NewFolder
End if

It even creates the folder without a problem if it is not there, but it won't copy the file! Just keeps saying permission denied. I even tried giving everyone write access on the server share to see if that was the problem, but that didn't do anything either. Any ideas?

Thanks.
rgtechsupportAsked:
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.

abbdanCommented:
User running the script must have Read and Write access to the running script location, write access to the copy destination and read access to the source of the script being coppied.
0
fostejoCommented:
rgtechsupport,

abbdan has probably hit the nail on the head, but you might also want to re-jig the logic in your script slightly to simplify it;

Set fso = CreateObject("Scripting.FileSystemObject")

NewFolder = "C:\Temp"

If NOT FSO.FolderExists( NewFolder ) then
     FSO.CreateFolder NewFolder
End if

fso.CopyFile "\\server\scripts\LanConnection.vbs", NewFolder

cheers,
0
rgtechsupportAuthor Commented:
Hey guys,

Oddly, I have given read and write access to the source scripts and to the destination location, but I still get the error! I changed the share permissions for the folder to Change for everyone and the NTFS to Modify for Users and the C:\Temp directory has Read and Write access for the user, but I still get permission denied! Both of the scripts are in the same server share. Any other ideas?

Thanks
0
fostejoCommented:
rgtechsupport,

Ok; think I've got it.. you need to tag a back slash onto the NewFolder variable; ie.

NewFolder = "C:\Temp\"

cheers

0

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
rgtechsupportAuthor Commented:
fostejo, that's it! Good eye, how did you figure it out? Thanks a lot! And also, I didn't have to give write access to the running script location, just read and it works fine! Thanks again!
0
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
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.