简体   繁体   English

使用 VBScript 的权限被拒绝

[英]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" error.在本地运行它是成功的,但是当尝试使用映射驱动器读取或写入目录时,该过程失败并出现“Permission Denied”错误。

Does VBScript not like mapped drives? VBScript 不喜欢映射驱动器吗? 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将文件夹复制到同一位置以检查用户权限

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM