Jump to content

Recommended Posts

Posted

Windows 7 System restore

 

Hi Guys,

 

Due to Steadystate not being supported on Windows 7 and comodo time machine causing Windows 7 to hang at shutdown I need some scripts.

 

I need a script that runs at student logoff that tells the computer to restore from the latest restore point. I have a script at the moment that nearly does it but it restores from a restore point numbered 20. Is there a way to edit this script so it just uses the latest restore point.

Thanks for any help.

 

 

Const RESTORE_POINT = 20

 

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default")

 

Set objItem = objWMIService.Get("SystemRestore")

errResults = objItem.Restore(RESTORE_POINT)

Posted

This should do what you want:

 

Option Explicit
On Error Resume Next

Dim objWMIService
Dim strComputer, intMaxSequenceNumber
Dim colRestorePoints, objRestorePoint

strComputer = "."
intMaxSequenceNumber = 0

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/default") 

Set colRestorePoints = objWMIService.ExecQuery("SELECT * FROM SystemRestore") 

If Not colRestorePoints Is Nothing Then
For Each objRestorePoint In colRestorePoints 
	If objRestorePoint.SequenceNumber > intMaxSequenceNumber Then
		intMaxSequenceNumber = objRestorePoint.SequenceNumber
	End If
Next
End If

If intMaxSequenceNumber <> 0 Then
Set colRestorePoints = objWMIService.ExecQuery("SELECT * FROM SystemRestore WHERE SequenceNumber = " & intMaxSequenceNumber) 

If Not colRestorePoints Is Nothing Then
	For Each objRestorePoint In colRestorePoints 
		'MsgBox "Restoring restore point #" & intMaxSequenceNumber
		objRestorePoint.Restore(intMaxSequenceNumber)
		Exit For
	Next
End If
End If

  • Thanks 2
Posted
Thanks Chris, lifesaver, I'm off to Thailand for three weeks tommorrow so wanted to get this nailed down before I went.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...