System Restore Scripts
Conducting a System RestoreCreating a System Restore Point
Disabling Full System Restore
Enabling Full System Restore
Getting the Results of the Last System Restore
Setting System Restore Configuration Values
Viewing All Existing Restore Points
Viewing System Restore Configuration Values
Conducting a System Restore
Performs a system restore on a computer using system restore point No. 20. To perform a system restore using a different system restore point, simply change the value of the constant RESTORE_POINT.
Const RESTORE_POINT = 20 strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default") Set objItem = objWMIService.Get("SystemRestore") errResults = objItem.Restore(RESTORE_POINT) Wscript.Echo errResults
Creating a System Restore Point
Creates a new system restore point on a computer, specifying that the restore point was created prior to installing a new device driver.
CONST DEVICE_DRIVER_INSTALL = 10 CONST BEGIN_SYSTEM_CHANGE = 100 strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default") Set objItem = objWMIService.Get("SystemRestore") errResults = objItem.CreateRestorePoint _ ("Scripted restore", DEVICE_DRIVER_INSTALL, BEGIN_SYSTEM_CHANGE) Wscript.Echo errResults
Disabling Full System Restore
Disables system restore on a computer. This is equivalent to selecting the checkbox Turn off System Restore (found by right-clicking My Computer, clicking Properties, and then clicking on the System Restore tab in the resulting dialog box).
strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default") Set objItem = objWMIService.Get("SystemRestore") errResults = objItem.Disable("") Wscript.Echo errResults
Enabling Full System Restore
Enables system restore on a computer. This is equivalent to clearing the checkbox Turn off System Restore (found by right-clicking My Computer, clicking Properties, and then clicking on the System Restore tab in the resulting dialog box).
strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default") Set objItem = objWMIService.Get("SystemRestore") errResults = objItem.Enable("") Wscript.Echo errResults
Getting the Results of the Last System Restore
Returns the results (failed, succeeded, interrupted) of the last system restore performed on a computer.
strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default") Set objItem = objWMIService.Get("SystemRestore") errResults = objItem.GetLastRestoreStatus() Select Case errResults Case 0 strRestoreStatus = "The last restore failed." Case 1 strRestoreStatus = "The last restore was successful." Case 2 strRestoreStatus = "The last restore was interrupted." End Select Wscript.Echo strRestoreStatus
Setting System Restore Configuration Values
Const GLOBAL_INTERVAL_IN_SECONDS = 100000 Const LIFE_INTERVAL_IN_SECONDS = 8000000 Const SESSION_INTERVAL_IN_SECONDS = 500000 strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default") Set objItem = objWMIService.Get("SystemRestoreConfig='SR'") objItem.DiskPercent = 10 objItem.RPGlobalInterval = GLOBAL_INTERVAL_IN_SECONDS objItem.RPLifeInterval = LIFE_INTERVAL_IN_SECONDS objItem.RPSessionInterval = SESSION_INTERVAL_IN_SECONDS objItem.Put_
Const GLOBAL_INTERVAL_IN_SECONDS = 100000 Const LIFE_INTERVAL_IN_SECONDS = 8000000 Const SESSION_INTERVAL_IN_SECONDS = 500000 strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default") Set objItem = objWMIService.Get("SystemRestoreConfig='SR'") objItem.DiskPercent = 10 objItem.RPGlobalInterval = GLOBAL_INTERVAL_IN_SECONDS objItem.RPLifeInterval = LIFE_INTERVAL_IN_SECONDS objItem.RPSessionInterval = SESSION_INTERVAL_IN_SECONDS objItem.Put_
Viewing All Existing Restore Points
Returns a list of all system restore points stored on a computer, as well as detailed information about each of those restore points.
Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime") strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default") Set colItems = objWMIService.ExecQuery("Select * from SystemRestore") If colItems.Count = 0 Then WScript.Echo "No restore point in system." Else For Each objItem in colItems Wscript.Echo "Name: " & objItem.Description Wscript.Echo "Number: " & objItem.SequenceNumber Select Case objItem.RestorePointType Case 0 strRestoreType = "Application installation" Case 1 strRestoreType = "Application uninstall" Case 6 strRestoreType = "Restore" Case 7 strRestoreType = "Checkpoint" Case 10 strRestoreType = "Device drive installation" Case 11 strRestoreType = "First run" Case 12 strRestoreType = "Modify settings" Case 13 strRestoreType = "Cancelled operation" Case 14 strRestoreType = "Backup recovery" Case Else strRestoreType = "Unknown" End Select Wscript.Echo "Restore Point Type: " & strRestoreType dtmConvertedDate.Value = objItem.CreationTime dtmCreationTime = dtmConvertedDate.GetVarDate Wscript.Echo "Time: " & dtmCreationTime Next End If
Viewing System Restore Configuration Values
Displays the current system restore configuration settings on a computer.
strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default") Set colItems = objWMIService.ExecQuery("Select * from SystemRestoreConfig") For Each objItem in colItems Wscript.Echo "Disk Percent: " & objItem.DiskPercent Wscript.Echo "Global Interval (in seconds): " & objItem.RPGlobalInterval Wscript.Echo "Life Interval (in seconds): " & objItem.RPLifeInterval If objItem.RPSessionInterval = 0 Then Wscript.Echo "Session Interval: Feature not enabled." Else Wscript.Echo "Session Interval (in seconds): " & _ objItem.RPSessionInterval End If Next