Tuesday, January 31, 2017

Creating a Restore Point Using Windows Management Instrumentation WMI and C NET

Creating a Restore Point Using Windows Management Instrumentation WMI and C NET


I have tried to find a way to create a restore point in Windows, but no matter how hard I tried, I just cant 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("\localhostrootdefault");
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. Dont forget to add System.Management as a reference!

Available link for download