CopyFile 上的 VBScript 权限被拒绝

发布于 2024-09-04 23:21:20 字数 1337 浏览 2 评论 0原文

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

仅供参考:“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

I'm running a VBScript in SQL Agent but I get a 'Permission Denied' on line 34 (the first copy attempt). I've run this script outside SQL Agent with no problems

FYI: The 'X:\' drive is mapped to a SharePoint folder. This may be the culprit.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梅倚清风 2024-09-11 23:21:20

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

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

The agent probably runs under a different user-account (i.e. not you) and then doesn't have permissions to the files/folders you're using.

When you run it outside, it uses your logged on user's permissions and executes fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文