Permission Denied Using VBScript
I have a script which will move and rename folders. It is successful when running it locally but when attempting to read or write to directories using mapped drives the process fails with a "Permission Denied" er开发者_开发技巧ror.
Does VBScript not like mapped drives? Below is the script with credentials to read and write to source and destination:
dim objNetwork
Set objNetwork = WScript.CreateObject("WScript.Network")
strLocalDrive = "Y:"
strRemoteShare = "\\servername\directory"
strPer = "False"
strUsr = "userid"
strPas = "password"
objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas
Dim fso, objFol, objMoveFol, strPathBuild
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFol = fso.GetFolder("D:\Source")
For Each objMoveFol In objFol.SubFolders
'Replace the root folder locations in the path
strPathBuild = Replace(objMoveFol, "D:\Source", "Y:\Destination")
'Do the required other fiddle
strPathBuild = Replace(strPathBuild, "A.", "Ack~")
fso.Movefolder objMoveFol, strPathBuild
Next
The code looks fine. Also if it is working locally I would guess that the user you are mapping the network drive with does not have permission to edit the folder.
Try mapping the drive manually with the same username and password. Copy a folder to the same location to check the users permissions
精彩评论