【问题标题】:Enable system protection using visual basic script on windows 8/10在 Windows 8/10 上使用 Visual Basic 脚本启用系统保护
【发布时间】:2017-06-14 21:48:43
【问题描述】:

我正在尝试在 Windows 10 上使用以下 Visual Basic 脚本启用系统保护。但它给出了“拒绝访问”错误。我搜索了有关 WMI 类的 Microsoft 文档,感觉以下代码对于 Windows 7 或 xp 来说非常好,但不适用于 Windows 10,并且在花费大量时间在 microsoft 网站上查找文档之后,我无法找到任何如何做到这一点的线索。

注意:我正在寻找一个可以在 Windows 10 上启用保护的 Visual Basic 脚本(如果不是)。

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default")

Set objItem = objWMIService.Get("SystemRestore")
errResults = objItem.Enable("D:\")

'Inform User that the task is done.
Mybox = MsgBox("System Restore is now enabled on "& strComputer &""  & 
vbCRLF ,vbOkOnly,"System Restore Enabled")

【问题讨论】:

  • 我已将用户帐户控制设置为“从不通知”。
  • 您仍然需要“以管理员身份运行”才能使脚本正常工作。见herehere
  • 我试过了,但还是不行。

标签: windows vbscript wmi system-restore


【解决方案1】:

我已经明白了。以下代码在 Windows 10 中成功启用系统保护。

If Not WScript.Arguments.Named.Exists("elevate") Then
    CreateObject("Shell.Application").ShellExecute WScript.FullName _
    , WScript.ScriptFullName & " /elevate", "", "runas", 1
    WScript.Quit
End If
Dim  oSR
Set oSR = GetObject("winmgmts:
{impersonationLevel=impersonate}!root/default:SystemRestore")
oSR.Enable("D:" & "\")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-24
    • 2021-04-25
    • 2014-05-22
    • 2013-04-15
    相关资源
    最近更新 更多