+ Post New Thread
Results 1 to 3 of 3
Scripts Thread, System Restore Scripts in Coding and Web Development; Windows 7 System restore Hi Guys, Due to Steadystate not being supported on Windows 7 and comodo time machine causing ...
  1. #1

    Join Date
    Oct 2005
    Location
    Bangkok
    Posts
    232
    Thank Post
    15
    Thanked 32 Times in 23 Posts
    Rep Power
    23

    System Restore Scripts

    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)

  2. #2

    Join Date
    Mar 2011
    Location
    Bournemouth
    Posts
    280
    Thank Post
    16
    Thanked 74 Times in 64 Posts
    Rep Power
    21
    This should do what you want:

    Code:
    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

  3. Thanks to ChrisMiles from:

    Jose (13th July 2011)

  4. #3

    Join Date
    Oct 2005
    Location
    Bangkok
    Posts
    232
    Thank Post
    15
    Thanked 32 Times in 23 Posts
    Rep Power
    23
    Thanks Chris, lifesaver, I'm off to Thailand for three weeks tommorrow so wanted to get this nailed down before I went.

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 7
    Last Post: 3rd May 2011, 08:54 AM
  2. Full system restore and AD woes
    By synaesthesia in forum Windows Server 2008
    Replies: 1
    Last Post: 2nd February 2011, 12:31 PM
  3. Replies: 10
    Last Post: 9th June 2010, 10:32 AM
  4. Missing System Restore + Update Problems
    By ste78564 in forum Windows
    Replies: 4
    Last Post: 28th September 2009, 04:30 PM
  5. Server 2003 System Restore
    By Ric_ in forum Windows
    Replies: 5
    Last Post: 11th October 2006, 09:20 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •