Programmatically create “System Restore Point”


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

Once the function finishes, navigate to your system restore point maker, you should see the name of the restore point you’ve just created from your application.

About these ads

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 64 other followers

%d bloggers like this: