[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4845
  • Last Modified:

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.
0
rgtechsupport
Asked:
rgtechsupport
  • 2
  • 2
1 Solution
 
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
 
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now