October 31, 2010 Leave a comment
System Restore is a powerful feature used in windows operating systems to create backups of the current system state before installation of custom software and critical system changes so that in case of an error, the user will be able to go back to the point just before the system was changed.
Suppose you are developing a custom application and at a point in time your application needs to change some system settings. It would be a great idea if you can create a restore point from within your application without the need to notify the user to manually create a restore point.
To create a restore point from vb.net code, we will use the handy GetObject method to grab the system restore application and create an instance from it. Once we have a system restore variable in hand, we just need a call to CreateRestorePoint method passing in the name of the restore point. There are 2 more variables that you do not need to worry about, These are the RestorePointType and the EventType which have static values in most cases of 0 and 100 respectively. Note that the CreateRestorePoint method takes a few seconds to execute. Below is a simple implementation to create a test restore point:
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