2017-06-14 37 views
0

我試圖在Windows 10上使用以下可視基本腳本啓用系統保護。但它給出了一個錯誤「訪問被拒絕」。我搜索了關於WMI類的微軟文檔,感覺就像下面的代碼對於Windows 7或XP而言完全正常,但對於Windows 10並非如此,並且在微軟網站上查找文檔時花費了大量時間,我一直無法找到任何如何做到這一點的線索。在Windows上使用visual basic腳本啓用系統保護8/10

注意:我正在尋找一個可視化的基本腳本ony,如果不是,它可以在Windows 10上啓用保護。

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") 
+0

我已將用戶帳戶控制設置設置爲「從不通知」。 –

+0

您仍然需要「以管理員身份運行」才能使腳本正常工作。請參閱[這裏](https://stackoverflow.com/q/36458651/886887)和[這裏](https://stackoverflow.com/q/11980651/886887)。 –

+0

我曾嘗試過,但它仍然無法正常工作。 –

回答

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:" & "\") 
相關問題