【问题标题】:Copying a file using VBS in to a Windows Directory, getting permission denied使用 VBS 将文件复制到 Windows 目录,获得权限被拒绝
【发布时间】:2013-10-27 22:46:38
【问题描述】:

我正在尝试为与我一起工作的一群计算机技能很少的人简化安装。我有一个 vbs 脚本,可以将各种配置文件复制到其正确的目录中。但是,我无法复制一个文件。

我正在尝试将一个名为 hosts 的新文件复制到 C:\windows\systems32\drivers\etc 文件夹中,但无论我做什么,我都会不断收到权限被拒绝。

Const OverWriteExisting = True
Dim fso

Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile "C:\users\IBM_ADMIN\Desktop\Colgate Socks\hosts", "C:\Windows\System32\drivers\etc\hosts", OverWriteExisting

有什么想法吗?

【问题讨论】:

  • 我假设您是从 shell(即命令提示符)运行它?如果是这样,您是否使用“以管理员身份运行”来启动 shell?
  • 如果所有计算机都在域中,您需要使用“域管理员”成员的帐户运行它。

标签: vbscript attributes permission-denied file-copying


【解决方案1】:

以管理员身份运行?

您可以通过任务调度器轻松做到这一点。

另一个选项来自How to run scripts as administrator in Windows 7?

把它放在脚本的开头

Set WshShell = WScript.CreateObject("WScript.Shell")
If WScript.Arguments.length = 0 Then
Set ObjShell = CreateObject("Shell.Application")
ObjShell.ShellExecute "wscript.exe", """" & _
WScript.ScriptFullName & """" &_
 " RunAsAdministrator", , "runas", 1
Else
[your code here]
end if

【讨论】:

    【解决方案2】:

    使用此 %windir%\Sysnative 而不是 C:\Windows\System32。

    【讨论】:

      猜你喜欢
      • 2018-08-03
      • 2014-09-17
      • 1970-01-01
      • 2011-03-29
      • 2013-04-10
      • 1970-01-01
      • 1970-01-01
      • 2018-12-10
      • 1970-01-01
      相关资源
      最近更新 更多