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 , , 24 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!

24 comments:

  1. Anonymous12: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)

    ReplyDelete
  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.

    ReplyDelete
  3. Beberapa tips cara menggugurkan kandungan dengan asam jawa untuk anda dengan menggunakan obat penggugur kandungan cytotec , terbukti dengan cepat untuk cara mencegah kehamilan . Maka dari itu pilihlah obat aborsi sangat ampuh . Jika anda telah haid obat telat datang bulan juga manjur , kami jual obat aborsi ini secara online cara menggugurkan hamil

    ReplyDelete
  4. Wonderful thanks for sharing an amazing idea. keep it...

    Learn Best Informatica Training in Bangalore from Experts. Softgen Infotech offers the Best Informatica Training in Bangalore.100% Placement Assistance, Live Classroom Sessions, Only Technical Profiles, 24x7 Lab Infrastructure Support.

    ReplyDelete
  5. Such a great information for blogger i am a professional blogger thanks…

    Learn Best Informatica Training in Bangalore from Experts. Softgen Infotech offers the Best Informatica Training in Bangalore.100% Placement Assistance, Live Classroom Sessions, Only Technical Profiles, 24x7 Lab Infrastructure Support.

    ReplyDelete
  6. Thank you for sharing such a nice post!

    Softgen Infotech is a leading training institute for all kind of the Best Python Training in Bangalore with real-time experienced trainers with 100% Placement Assistance.

    ReplyDelete