如何以编程方式创建系统还原点? [英] How to create a system restore point programmatically?

查看:101
本文介绍了如何以编程方式创建系统还原点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种通过按下按钮来使用当前日期和时间创建系统还原点的方法.我曾尝试在网络上搜索一种简单的方法来执行此操作,但还没有找到.

I'm looking for a way to create a system restore point with the current date and time by pressing a button. I've tried searching the web for a simple way to do this but I haven't found one yet.

我从以下位置找到了此代码段:

I found this code snippet from: http://msdn.microsoft.com/en-us/library/windows/desktop/aa378847%28v=vs.85%29.aspx but it is in VB and not C#, I tried converting it a bit but I don't think i'm doing a great job of translating it.

'CreateRestorePoint Method of the SystemRestore Class
'Creates a restore point. Specifies the beginning and 
'the ending of a set of changes so that System Restore 
'can create a restore point.This method is the 
'scriptable equivalent of the SRSetRestorePoint function.

Set Args = wscript.Arguments
If Args.Count() > 0 Then
    RpName = Args.item(0)
Else 
    RpName = "Vbscript"
End If

Set obj = GetObject("winmgmts:{impersonationLevel=impersonate}!root/default:SystemRestore")

If (obj.CreateRestorePoint(RpName, 0, 100)) = 0 Then
wscript.Echo "Success"
Else 
    wscript.Echo "Failed"
End If

推荐答案

下面是创建还原点的VB.NET代码段(在

Here's a VB.NET snippet to create a restore point (found here):

Dim restPoint = GetObject("winmgmts:\\.\root\default:Systemrestore")
If restPoint IsNot Nothing Then
     If restPoint.CreateRestorePoint("test restore point", 0, 100) = 0 Then
         MsgBox("Restore Point created successfully")
    Else
         MsgBox("Could not create restore point!")
     End If
End If

应该很容易翻译"为C#.

Should be easy to "translate" to C#.

这是C#中的另一个摘录,摘录自这个问题:

And here's another snippet in C# taken from this question:

private void CreateRestorePoint(string description)
{
    ManagementScope oScope = new ManagementScope("\\\\localhost\\root\\default");
    ManagementPath oPath = new ManagementPath("SystemRestore");
    ObjectGetOptions oGetOp = new ObjectGetOptions();
    ManagementClass oProcess = new ManagementClass(oScope, oPath, oGetOp);

    ManagementBaseObject oInParams =
         oProcess.GetMethodParameters("CreateRestorePoint");
    oInParams["Description"] = description;
    oInParams["RestorePointType"] = 12; // MODIFY_SETTINGS
    oInParams["EventType"] = 100;

    ManagementBaseObject oOutParams =
         oProcess.InvokeMethod("CreateRestorePoint", oInParams, null); 
}

这篇关于如何以编程方式创建系统还原点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆