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

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.


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
set name=%1
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%

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.