VBS中对CopyFile的权限被拒绝

VBS中对CopyFile的权限被拒绝

本文介绍了VBS中对CopyFile的权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自动将文件推送到用户的主目录中,但是卡在权限被拒绝"错误中-在此处的第6行,通过CopyFile调用引发该错误.

I'm trying to automate pushing a file into my users' home directories, but am stuck on a "Permission Denied" error — is thrown on line 6 here, with the CopyFile call.

脚本的其他部分(未显示)使用相同的源目录和目标目录创建和复制文件夹内容,并且它们运行良好.只有当我使用CopyFile时,它才会失败.

There are other parts of the script (not shown) that create and copy folder contents using the same source and destination directories, and they work perfectly. It's only when I use CopyFile that it fails.

Dim fso

Set fso = CreateObject("Scripting.FileSystemObject")

If Not fso.FileExists("H:\Minecraft\.minecraft\options.txt") Then
    fso.CopyFile "C:\Minecraft\options.txt", "H:\Minecraft\.minecraft\"
End If

Set fso = Nothing

H:是网络主目录,当前用户对其具有完整的读/写特权.

H: is a network home directory, to which the current user has full read/write privs.

我尝试从路径中添加/删除尾部斜杠,将"options.txt"添加到目标路径,删除false参数...不知道还要尝试什么.有什么想法吗?

I've tried adding/removing trailing slashes from the paths, adding "options.txt" to the destination path, removing the false argument... Not sure what else to try. Any thoughts?

FYI,紧接在上面容易出错的位之前的这段代码,每次都能完美执行:

FYI, this chunk of code, which comes immediately before the error-prone bit above, executes perfectly every time:

If Not fso.FolderExists("H:\Minecraft\.minecraft\bin\") Then
    If Not fso.FolderExists("H:\Minecraft\.minecraft\") Then
        fso.CreateFolder("H:\Minecraft\.minecraft\")
    End If
    fso.GetFolder("C:\Minecraft\bin\").Copy "H:\Minecraft\.minecraft\"
End If

推荐答案

我只见过 CopyFile 失败,并显示"permission否认"错误:

I've only ever seen CopyFile fail with a "permission denied" error in one of these 3 scenarios:

  • 源或目标的实际许可问题.
  • 目标路径是一个文件夹,但没有结尾的反斜杠.
  • 源文件已被应用程序锁定.

这篇关于VBS中对CopyFile的权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 15:15