Create a System Restore Point with VBscript

By | 2013-10-25

This handy little VBscript to create a system restore point can be encapsulated in a function and can save you from yourself.

Lets say you’re performing some automated functions on a group of machines.  Some of these operations might be changing/adding/deleting registry files, or making changes to drivers, or even (gasp!) fiddling with key system files.  One way to protect yourself is to perform a backup or image of the machine before starting.

But there is another way.  You can leverage the built-in feature of Windows to create system restore points, which will allow you to back out any changes that might have backfired in your script.  Watch out for line wrap below:

CONST DEVICE_DRIVER_INSTALL = 10
CONST BEGIN_SYSTEM_CHANGE = 100
strComputer = "TARGET COMPUTERNAME HERE"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default")
Set objItem = objWMIService.Get("SystemRestore")
errResults = objItem.CreateRestorePoint("Scripted restore", DEVICE_DRIVER_INSTALL, BEGIN_SYSTEM_CHANGE)

There you go.  Pretty straightforward, yes?  Hope this helps you out.

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.