Subscribe to Windows IT Pro
January 26, 2005 12:00 AM

JSI Tip 8975. How can I create a Restore Point in Windows XP, from the command-line, or from a batch?

Windows IT Pro
InstantDoc ID #82869
Rating: (1)

I described the process of creating and using a Restore Point in tip 4650 » How do I use Windows XP Professional's System Restore to undo problem changes.

I have scripted CrtRP.bat to create a Restore Point from the command-line, or from a batch.

The syntax for using CrtRP.bat is:

CrtRP Description RetVal

Where Description is the Restore point description and RetVal is a call directed environment variable that will contain a Y if the Restore Point was successfully created, or an N if the Restore Point creation failed.

Example:

CrtRP "Test CrtRP.bat" OK
If "%OK%" EQU "N" Goto RPFailed

NOTE: See the following tips:

How can I retrieve all the available Restore Points on a Windows XP Professional computer?
How can I restore a Windows XP Professional Restore Point from the command-line, or from a batch?
How can I test the status of the last Windows XP Professional System Restore?
How can I use the command-line, or a batch, to disable Windows XP Professional System Restore on one or all drives?

CrtRP.bat contains:

@echo off
if {%2}=={} @echo Syntax: CrtRP Description RetVal&goto :EOF
setlocal
set name=%1
set CrtRPVBS="%TEMP%\CrtRP_%RANDOM%.VBS"
set OK=N
@echo Set objArguments = Wscript.Arguments>%CrtRPVBS%
@echo CrtRPn = objArguments(0)>>%CrtRPVBS%
@echo Set obj = GetObject("winmgmts:{impersonationLevel=impersonate}!root/default:SystemRestore")>>%CrtRPVBS%
@echo If (obj.CreateRestorePoint(CrtRPn, 0, 100)) = 0 Then>>%CrtRPVBS%
@echo     wscript.Echo "Y">>%CrtRPVBS%
@echo Else>>%CrtRPVBS%
@echo     wscript.Echo "N">>%CrtRPVBS%
@echo End If>>%CrtRPVBS%
for /f "Tokens=*" %%r in ('cscript //nologo %CrtRPVBS% %name%') do (
 set OK=%%r
)
del /q %CrtRPVBS%
endlocal&set %2=%OK%



Related Content:

ARTICLE TOOLS

Comments
  • Thorsten Albrecht
    2 years ago
    Mar 17, 2010

    Thanks for the batch script.
    For those who would like to make a system restore point directly in vbs please have a look to:
    http://msdn.microsoft.com/en-us/library/aa378847%28VS.85%29.aspx

    ... or use the following vbs script.
    ----- begin---

    ' source:
    ' http://msdn.microsoft.com/en-us/library/aa378847%28VS.85%29.aspx

    'CreateRestorePoint Method of the SystemRestore Class
    'Creates a restore point. Specifies the beginning and
    'the ending of a set of changes so that System Restore
    'can create a restore point.This method is the
    'scriptable equivalent of the SRSetRestorePoint function.

    ' call this script directly or per dos batch:
    ' cscript //nologo create_system_restore_msnlib.vbs my_description

    ' v0.1 100317 Thorsten Albrecht, confirmation box switch added
    ' tested in Windows 7 Professional x64, should work in xp, too

    ' restore system restore points with: rstrui.exe

    '----------------------------------------------------
    ' user options:
    show_confirmation = 0 '0: don't show any success window with confirmation button
    ' 1: display a confirmation dialogue after creating the system restore point

    '----------------------------------------------------
    Set Args = wscript.Arguments

    If Args.Count() > 0 Then
    RpName = Args.item(0)
    Else
    RpName = "created system restore point through vbs script create_system_restore_msnlib.vbs"
    End If

    Set obj = GetObject("winmgmts:{impersonationLevel=impersonate}!root/default:SystemRestore")

    If (obj.CreateRestorePoint(RpName, 0, 100)) = 0 Then
    result = 0 'success
    Else
    result = 1 'failure
    End If

    If (show_confirmation = 1) Then
    If (result = 0) Then
    wscript.Echo "Created system restore point successfully."
    Else
    wscript.Echo "Error while creating system restore point!"
    End If
    End If


    -----end -----

    Thorsten

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.