yet another blog about computer, technology, programming, and internet

Tuesday, June 27, 2006

Creating a Restore Point Using Windows Management Instrumentation (WMI) and C#.NET

Tuesday, June 27, 2006 Posted by Ismail Habib , , 37 comments
I have tried to find a way to create a restore point in Windows, but no matter how hard I tried, I just can't find the one using C#, one of my favourite language. Sigh, I have to make one on my own :P Windows has something called WMI (Windows Management Instrumentation). It contains a huge classes and objects that allow programmers to do a lot of things, creating a restore point is just one of them.
Here is the source code to create a restore point in Windows:

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"] = "My Restore Point";
oInParams["RestorePointType"] = 0;
oInParams["EventType"] = 100;

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

Hope this will be useful. Don't forget to add System.Management as a reference!


  1. Tester12:17 AM

    I get an error on Vista using above code.

    Unhandled Exception: System.Runtime.InteropServices.COMException (0x800423F4)
    at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode
    , IntPtr errorInfo)
    at System.Management.ManagementObject.InvokeMethod(String methodName, Managem
    entBaseObject inParameters, InvokeMethodOptions options)

  2. Thanks for the comment. Unfortunately, this code is written for Windows XP and I am not sure if it's going to work in another version of Windows.

  3. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.
    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.