0

我正在尝试在 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")
4

1 回答 1

0

我已经想通了。以下代码在 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:" & "\")
于 2017-06-15T08:28:59.940 回答