private void MountRP_Click(object sender, RoutedEventArgs e) { MessageBoxResult result; SystemRestorePoint SelectedItem = (SystemRestorePoint)listView.SelectedItem; if (SelectedItem == null) { MessageBox.Show("请选择一个系统还原点", "NWSRMgr"); } else { int RPNum = SelectedItem.SequenceNumber; string[] array = SelectedItem.DeviceObject.Split(new char[] { '\\' }); string LinkName = Environment.ExpandEnvironmentVariables("%SystemDrive%") + "\\" + array[array.Length - 2]; if (!Directory.Exists(LinkName)) { result = MessageBox.Show( "确定挂载还原点" + RPNum.ToString(), "NWSRMgr", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No, MessageBoxOptions.DefaultDesktopOnly); if (result == MessageBoxResult.Yes) { CreateSymbolicLink(LinkName, SelectedItem.DeviceObject, 1); Process.Start(LinkName); } } else { result = MessageBox.Show( "还原点" + RPNum.ToString() + "存在,是否卸载还原点", "NWSRMgr", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No, MessageBoxOptions.DefaultDesktopOnly); if (result == MessageBoxResult.Yes) { Directory.Delete(LinkName); } } } }
private void RestoreRP_Click(object sender, RoutedEventArgs e) { MessageBoxResult result; SystemRestorePoint SelectedItem = (SystemRestorePoint)listView.SelectedItem; if (SelectedItem == null) { MessageBox.Show("请选择一个系统还原点", "NWSRMgr"); } else { int RPNum = SelectedItem.SequenceNumber; result = MessageBox.Show( "确定从还原点" + RPNum.ToString() + "还原", "NWSRMgr", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No, MessageBoxOptions.DefaultDesktopOnly); if (result == MessageBoxResult.Yes) { if (SR.RestoreFromRestorePoint(RPNum)) { result = MessageBox.Show( "系统还原成功,是否重启电脑以继续", "NWSRMgr", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No, MessageBoxOptions.DefaultDesktopOnly); if (result == MessageBoxResult.Yes) { ExitWindows.Reboot(); } } else { MessageBox.Show("系统还原失败", "NWSRMgr"); } } } }
private void DeleteRP_Click(object sender, RoutedEventArgs e) { MessageBoxResult result; SystemRestorePoint SelectedItem = (SystemRestorePoint)listView.SelectedItem; if (SelectedItem == null) { MessageBox.Show("请选择一个系统还原点", "NWSRMgr"); } else { int RPNum = SelectedItem.SequenceNumber; result = MessageBox.Show( "确定删除还原点" + RPNum.ToString(), "NWSRMgr", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No, MessageBoxOptions.DefaultDesktopOnly); if (result == MessageBoxResult.Yes) { if (SR.DeleteRestorePoint(RPNum)) { MessageBox.Show( "还原点" + RPNum.ToString() + "删除成功", "NWSRMgr"); } else { MessageBox.Show( "还原点" + RPNum.ToString() + "删除失败", "NWSRMgr"); } } } }
public void RefreshList() { /*PS C:\windows\system32> get-wmiObject -class SystemRestore -namespace "root\default" * * CreationTime Description SequenceNumber EventType RestorePointType * ------------ ----------- -------------- --------- ---------------- * 2014/5/10 9:26:29 Good 18 BEGIN_SYSTEM_C... 9*/ //get-wmiObject -class Win32_ShadowCopy -namespace "root/CIMV2" listView.Items.Clear(); foreach (ManagementObject SRInfo in SR.SRObject.Get()) { SystemRestorePoint Item = new SystemRestorePoint(); Item.SequenceNumber = Convert.ToInt32(SRInfo["SequenceNumber"]); DateTime CreationTime = SR.ConvertTime(SRInfo["CreationTime"].ToString()).ToLocalTime(); Item.CreationTime = CreationTime.ToString(); try { Item.Description = SRInfo["Description"].ToString(); } catch { Item.Description = "未命名"; } Item.RestorePointType = SR.GetRestorePointType( Convert.ToInt32(SRInfo["RestorePointType"])); try { long minvalue = -1; foreach (ManagementObject VSSCopyInfo in SR.VSSCopyObject.Get()) { DateTime InstallTime = SR.ConvertTime(VSSCopyInfo["InstallDate"].ToString()); long value = Math.Abs(CreationTime.Ticks - InstallTime.Ticks); if (minvalue == -1 || value < minvalue) { Item.DeviceObject = VSSCopyInfo["DeviceObject"].ToString() + "\\"; minvalue = value; } } } catch { } listView.Items.Add(Item); } StatusLabel.Content = "已使用:"; try { long SRSize = SR.GetUsedSize(); string result; double num = SRSize >> 20; if (num > 1024) { result = string.Format("{0:0.0}", num / 1024) + " GB"; } else { result = string.Format("{0:0.0}", num) + " MB"; } StatusLabel.Content += result; } catch { StatusLabel.Content += "0 MB"; } StatusLabel.Content += "\r\n系统还原状态:"; if (SR.IsSREnabled()) { StatusLabel.Content += "开启"; SetStatusButton.Content = "禁用系统还原"; } else { StatusLabel.Content += "关闭"; SetStatusButton.Content = "启用系统还原"; } }