'
' Example script for 2BrightSparks SyncBackPro V8 that creates a
' Restore Point in Windows. If its a simulated run, or a restore,
' no restore point is created.
'
' In Windows you must have Administrator privileges to create
' restore points.
'
' SBLang=Basic
'
' http://www.2BrightSparks.com/
'

'
' This is a runtime script 
'
Function Description(ByRef ScriptType)
  Description = "Create a Restore Point in Windows when the profile run"
  ScriptType = SCRIPTTYPE_RUN
End Function

'
' We create the restore point before files are copied, deleted, etc.
' If it fails then we record a warning in the log.
'
Sub RunAfterConfig
  ' Restore or simulation?  
  If SBRunning.Restore or SBRunning.Simulated then
    Exit Sub
  End If

  ' Create restore point
  if not SBSystem.UpdateFileStatus("Creating restore point...") then
    Set obj = GetObject("winmgmts:{impersonationLevel=impersonate}!root/default:SystemRestore")
    ErrCode = obj.CreateRestorePoint("Restore point created SyncBackPro", 0, 100)
    If (ErrCode <> 0) Then
      SBLocation.Warning("Windows Restore Point", "Failed to create, error code " & CStr(ErrCode))
    End If
  end if
End Sub
