【问题标题】:VBScript Permission Denied on CopyFileCopyFile 上的 VBScript 权限被拒绝
【发布时间】:2010-06-09 19:05:17
【问题描述】:

我正在 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

【问题讨论】:

    标签: vbscript sql-agent


    【解决方案1】:

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

    当你在外面运行它时,它使用你登录用户的权限并且执行良好。

    【讨论】:

    • 我倾向于同意这个答案,但代理使用与我使用的用户相同的用户登录。
    猜你喜欢
    • 2013-04-10
    • 2019-01-18
    • 1970-01-01
    • 2015-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-01
    • 1970-01-01
    相关资源
    最近更新 更多