Paypal Donate

Disable System Restore

File
disablesr.vbs (2 views)

The attached script uses WMI to disable System Restore on Windows XP (it may work on Vista, but I haven't tried it).

The main function is DisableSystemRestore, and can be called with a computer name (or "." for the local computer) by itself.  In this script, the function is used with a text file that contains a list of computers - an administrator can then use the script to disable system restore on a number of computers.  A log is written that reports the success or failure of the action on each computer.

' Script written by David Barrett
' Copyright 2009
' http://www.cedit.biz/
'
This script is licensed under the Creative Commons
' Attribution 2.5 Licence
' http://creativecommons.org/licenses/by/2.5/
'

' You are free to use it for both personal and
' commercial purposes, so long as full attribution
' is given to the author (David Barrett).
'
' This notice must not be removed
'
'
dim strComputerList
strComputerList="c:\computers.txt" ' Change to the file containing list of computers
strLogFile="c:\log.txt" ' Change to the location of the log file (will be wiped/created each time)

dim objFSO, objF
dim strResults
strResults=""

set objFSO=CreateObject("Scripting.FileSystemObject")
if objFSO.FileExists(strComputerList) then
    set objF=objFSO.OpenTextFile(strComputerList,1)
    while not objF.AtEndOfStream
        strResults=strResults & DisableSystemRestore(objF.ReadLine)
    wend
    objF.Close
end if
set objF=objFSO.CreateTextFile(strLogFile,true)
objF.Write strResults
objF.Close
set objF=Nothing
set objFSO=Nothing


function DisableSystemRestore(strComputer)
    dim objWMI, objItem, errResults
    on error resume next
    Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default")
 
    Set objItem = objWMI.Get("SystemRestore")
    if Err.Number=0 then
        errResults = objItem.Disable("")
    else
        errResults=-1 ' Failed to get WMI object
        Err.Clear
    end if
    if errResults=0 then
        DisableSystemRestore=strComputer & ": SUCCESS"
    else
        DisableSystemRestore=strComputer & ": FAIL"
    end if
end function
  
Copyright © 2009 www.cedit.biz. All rights reserved.