Disable-ComputerRestore 不会关闭系统保护

发布于 2024-12-22 14:46:32 字数 218 浏览 2 评论 0原文

我正在以编程方式尝试在 Windows 7 中启用/禁用系统还原。我已启用系统还原工作“Enable-ComputerRestore”,但禁用给我带来了问题。

Disable-ComputerRestore -drive "C:\"

没有将我的 C: 驱动器设置为“关闭系统保护”。它将其设置为“仅恢复文件的先前版本”。任何人都知道为什么会发生这种情况?

I'm programmatically trying to enable/disable System Restore in Windows 7. I have enable system restore working "Enable-ComputerRestore", but disable is giving me issues.

Disable-ComputerRestore -drive "C:\"

doesn't set my C: drive to "Turn off system protection". It sets it to "Only restore previous versions of files" instead. Anyone have a clue as to why this could be happening?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒废 2024-12-29 14:46:32

您只需以管理员身份在本地(无需远程)执行此操作:

在此处输入图像描述

命令

在此处输入图像描述

注意,您必须关闭系统属性windo并重新打开它才能看到结果。

在此处输入图像描述

You just have to do it localy (no remote) as administrator :

enter image description here

The command

enter image description here

Be careful, you have to close the system properties windo and reopen it to see the result.

enter image description here

深海夜未眠 2024-12-29 14:46:32

我正在使用 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);
        }
    }

I'm solving this using WMI and the following C# code adapted from here.

    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);
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文