繁体   English   中英

在CopyFile上拒绝VBScript权限

[英]VBScript Permission Denied on CopyFile

我在SQL Agent中运行VBScript,但在第34行(第一次尝试复制)上收到“权限被拒绝”。 我已经在SQL Agent外部运行了该脚本,没有任何问题

仅供参考:“ X:\\”驱动器已映射到SharePoint文件夹。 这可能是罪魁祸首。

Function Main()
Const SourceDrive As String = "X:\"
Dim fso
Dim Today
Dim FileName
Dim FromFile
Dim FromDrive
Dim ArchivePath

Set fso = CreateObject("Scripting.FileSystemObject")

Today = Format(Now, "yyyyMMdd")

'To add more sources just add them to the array list
Dim Sources() As Variant
Sources() = Array("Item1", _
                  "Item2")

'To add more targets just add them to the array list
Dim Targets() As Variant
Targets() = Array("C:\Users\myalias\Desktop\MyToFolder", _
                  "C:\Users\myalias\Desktop\MyToFolder2")


For i = 0 To UBound(Sources)
    FileName = "WebSurveyAlertCallbacks_" & Sources(i) & "_" & Today & ".xls"
    FromDrive = fso.BuildPath(SourceDrive, Sources(i))
    FromFile = fso.BuildPath(FromDrive, FileName)
    ArchivePath = fso.BuildPath(FromDrive, "Archive")
    If fso.FileExists(FromFile) Then
        For t = 0 To UBound(Targets)
            fso.CopyFile FromFile, fso.BuildPath(Targets(t), FileName), True
        Next
        fso.CopyFile FromFile, fso.BuildPath(ArchivePath, FileName), True
        fso.DeleteFile FromFile
    End If
Next

Set fso = Nothing

Main = DTSTaskExecResult_Success
End Function

该代理可能在不同的用户帐户下运行(即不是您),然后没有使用的文件/文件夹的权限。

当您在外部运行它时,它会使用您登录用户的权限并执行良好。

暂无
暂无

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

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