如何创建一个系统编程还原点? [英] How to create a system restore point programatically?

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

问题描述

我正在寻找一种方式来创建一个系统的当前日期和时间按下按钮还原点。我试着在网上搜索了一个简单的方法来做到这一点,但我还没有找到一个还没有。



我发现这个代码片段来自:的 http://msdn.microsoft.com/en-us/library/windows/desktop/aa378847%28v=vs.85%29.aspx 但它在VB,而不是C#中,我试着将它转换了一点,但我不认为我做翻译的是一个伟大的工作。

 '的系统还原类
的CreateRestorePoint方法创建一个还原点。指定的开始和
'一组更改的结局,使系统还原
'可以创建一个恢复point.This方法是
'的与SRSetRestorePoint功能的脚本的等价物。

组参数数量= wscript.Arguments
。如果Args.Count()> 0,那么
RpName = Args.item(0)
,否则
RpName =VBSCRIPT
端如果

组的obj = GetObject的(winmgmts: {impersonationLevel =冒充}根/默认:系统还原)

。如果(obj.CreateRestorePoint(RpName,0,100))= 0,那么
wscript.Echo成功
,否则
wscript.Echo失败
端如果


解决方案

下面是一个VB.NET代码片段来创建一个还原点(发现的>):

 暗淡restPoint = GetObject的(winmgmts:\\.\\ \\root\default:系统还原)
如果restPoint状态并没有任何然后
如果restPoint.CreateRestorePoint(测试还原点,0,100)= 0,那么
MSGBOX(还原点创建成功)
,否则
MSGBOX(无法创建还原点!)
端如果
端如果

应该很容易翻译为C#。



这是在C#中的另一个片段从的这个问题

 私人无效CreateRestorePoint(字符串描述)
{
的Oscope管理范围=新管理范围(\\\\localhost\\root\\default) ;
ManagementPath OPATH =新ManagementPath(系统还原);
ObjectGetOptions oGetOp =新ObjectGetOptions();
ManagementClass oProcess =新ManagementClass(oscope需要,OPATH,oGetOp);

ManagementBaseObject oInParams =
oProcess.GetMethodParameters(CreateRestorePoint);
oInParams [说明] =说明;
oInParams [RestorePointType] = 12; // MODIFY_SETTINGS
oInParams [事件类型] = 100;

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


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

解决方案

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

Should be easy to "translate" to 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天全站免登陆