簡體   English   中英

Disable-ComputerRestore不會關閉系統保護

[英]Disable-ComputerRestore doesn't turn off system protection

我正在以編程方式嘗試在Windows 7中啟用/禁用系統還原。我已經啟用了工作於“ Enable-ComputerRestore”的系統還原,但是禁用給我帶來了問題。

Disable-ComputerRestore -drive "C:\"

沒有將我的C:驅動器設置為“關閉系統保護”。 而是將其設置為“僅還原文件的先前版本”。 任何人都知道為什么會發生這種情況嗎?

您只需以管理員身份在本地進行設置(無遠程):

在此處輸入圖片說明

命令

在此處輸入圖片說明

注意,您必須關閉系統屬性windo,然后重新打開它才能看到結果。

在此處輸入圖片說明

我正在使用WMI和從此處改編的以下C#代碼來解決此問題。

    public void disableSystemRestore(string drive)
    {
        try
        {
            ManagementScope scope = new ManagementScope("\\\\localhost\\root\\default");
            ManagementPath path = new ManagementPath("SystemRestore");
            ObjectGetOptions options = new ObjectGetOptions();
            ManagementClass process = new ManagementClass(scope, path, options);
            ManagementBaseObject inParams = process.GetMethodParameters("Disable");
            inParams["Drive"] =  drive;
            ManagementBaseObject outParams = process.InvokeMethod("Disable", inParams, null);
        }
        catch(ManagementException err)
        {
            MessageBox.Show("An error occurred while trying to execute the WMI method: " + err.Message);
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM