在C#中检查系统还原状态的方法
我正在检查系统还原状态检查(启用/禁用)。 研发后我发现它可以通过以下方式完成:
- 状态检查srclient.dll
- 编辑Registery Keys
- WMI可用到XP版本..
1)我需要有关如何在C#中检查SystemRestore Registry中的注册表键值的帮助。
2)如果我需要使用C#库中的可用function设置或删除还原点,我的程序代码可以正常工作,但我想在用户设置或删除还原点之前检查状态。 如果有人帮忙找出解决方案,我将不胜感激。
这是我检查是否启用了系统还原的方法:
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"); }
要使用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);
- exception与validation
- 接口 – 在C#中实现匿名类?
- 如何使用C#选择CodeDom编译器的目标框架?
- Canonical:如何从Excel VBA调用.NET方法
- 使用MSIEnumRelatedProducts和MSIGetProductInfo的MSI Interop
- ODP.NET连接池参数
- Scaffolding EntityFramework 6无法将’System.Data.Entity.Core.Objects.ObjectContext’类型的对象强制转换为’System.Data.Objects.ObjectContext’
- 如何在MVC 4中的同一视图中打开窗口?
- 使用Json.Net将JSON解析为DataSet的问题