VBS 中的 CopyFile 权限被拒绝 [英] Permission denied on CopyFile in VBS

查看:69
本文介绍了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.minecraftoptions.txt") Then
    fso.CopyFile "C:Minecraftoptions.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, this chunk of code, which comes immediately before the error-prone bit above, executes perfectly every time:

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

推荐答案

我只见过 CopyFile 在以下 3 种情况之一中失败并出现权限被拒绝"错误:

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

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆