在C#中检查系统还原状态的方法

dij*_*jay 4 c#

我正在检查系统还原状态检查(启用/禁用).研发后我发现它可以通过以下方式完成:

  1. 状态检查srclient.dll
  2. 编辑登记密钥
  3. WMI-XP版本可用..

1)我需要有关如何在C#中检查SystemRestore Registry中的注册表键值的帮助.

2)如果我需要使用C#库中的可用功能设置或删除还原点,我的程序代码可以正常工作,但我想在用户设置或删除还原点之前检查状态.如果有人帮忙找出解决方案,我将不胜感激.

Pax*_*ime 5

这是我检查是否启用了系统还原的方法:

RegistryKey rk = Registry.LocalMachine;
RegistryKey rk1 = rk.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore");
string sysRestore = rk1.GetValue("RPSessionInterval").ToString();
if (sysRestore.Contains("1"))
{
    MessageBox.Show("System Restore is Enabled");
}

if (sysRestore.Contains("0"))
{
    MessageBox.Show("System Restore is Disabled");
}
Run Code Online (Sandbox Code Playgroud)

要使用WMI启用系统还原:

string osDrive = Path.GetPathRoot(Environment.SystemDirectory);

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("Enable");
inParams["WaitTillEnabled"] = true;
inParams["Drive"] = osDrive;
ManagementBaseObject outParams = process.InvokeMethod("Enable", inParams, null);
Run Code Online (Sandbox Code Playgroud)

  • 如何获取已启用系统还原的磁盘驱动器? (3认同)