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

Jerold Schulman

January 25, 2005

1 Min Read
ITPro Today logo in a gray background | ITPro Today

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 offif {%2}=={} @echo Syntax: CrtRP Description RetVal&goto :EOFsetlocalset name=%1set 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%



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like