【问题标题】:VBS access deniedVBS 访问被拒绝
【发布时间】:2012-07-17 02:29:39
【问题描述】:

我想制作一个可以将文件复制到c:\windows\system32\whatever.vbs 的程序。问题是我在运行时得到“拒绝访问”。

我已尝试获取管理员权限,但 UAC 仍然出现。谁能给我一个脚本以管理员身份运行我的 vbs 并在运行时禁用 UAC?

代码如下:

option explicit
dim folder, root, f1, source, destination, regedit, WshNetwork

function CopyFile(source, destination)
dim filesys

set filesys=CreateObject("Scripting.FileSystemObject")
  If filesys.FileExists(source) Then
     filesys.CopyFile source, destination
  End If
end function

Set WshNetwork = WScript.CreateObject("WScript.Network")

set folder = CreateObject("Scripting.FileSystemObject")
set root = folder.GetFile(Wscript.ScriptFullName)

source = root
destination = "c:\Documents And Settings\" & WshNetwork.UserName &"\Start Menu\Programs\Startup\whatever.vbs"

call CopyFile(source,destination)

destination = "c:\Windows\System32\whatever.vbs"  -> in here access is denied

call CopyFile(Source,destination)

【问题讨论】:

  • 我们无法通过代码修改 UAC 设置

标签: vbscript


【解决方案1】:

您需要以管理员身份运行此脚本,否则用户将拥有管理员权限:

runas /user:Administrator cscript vbscript.vbs

您也可以在提升的命令提示符中运行它或完全禁用 UAC:

reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v EnableLUA /t REG_DWORD /d 0 /f

...并重新启动系统。

没有办法以编程方式执行您所要求的操作。 UAC 的全部目的是“阻碍”此类脚本的运行并在进程尝试特权访问时发出警告。

【讨论】:

  • 对我来说,runas 在没有 cscript 的情况下工作:runas /user:Administrator vbscript.vbs
猜你喜欢
  • 2013-10-25
  • 2014-09-17
  • 1970-01-01
  • 2014-08-10
  • 2021-03-06
  • 2011-05-15
  • 2010-09-06
  • 2014-03-22
  • 2013-08-10
相关资源
最近更新 更多