Link to home
Start Free TrialLog in
Avatar of rgtechsupport
rgtechsupport

asked on

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.
Avatar of abbdan
abbdan

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.
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,
Avatar of rgtechsupport

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of fostejo
fostejo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!