JSI Tip 8977. How can I restore a Windows XP Professional Restore Point from the command-line, or from a batch?

Jerold Schulman

January 25, 2005

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

I have scripted RstRP.bat to restore a Windows XP Professional Restore Point from the command-line, or from a batch?

The syntax for using RstRP.bat is:

RstRP RPSeq

Where RPSeq is the Restore Point Sequence Number. If RPSeq is valid, RstRP.bat will shutdown and restart the computer to restore the Restore Point.

NOTE: If RstRP.bat returns to the process that invoked it, the Restore Point Sequence Number was invalid.

To restore the last Restore Point:

setlocalset RPSeq=Nfor /f "Tokens=*" %%a in ('enumRP') do ( call :erp %%a)if "%RPSeq%" EQU "N" goto noneRstRP %RPSeq%endlocalgoto :EOF:none@echo No Restore Points found.endlocalgoto :EOF:erpset RPSeq=%1

To restore the oldest Restore Point:

setlocalset RPSeq=Nfor /f "Tokens=*" %%a in ('enumRP') do ( call :erp %%a)if "%RPSeq%" EQU "N" goto noneRstRP %RPSeq%endlocalgoto :EOF:none@echo No Restore Points found.endlocalgoto :EOF:erpif "%RPSeq%" EQU "N" set RPSeq=%1

To restore the last Restore Point taken on January 20, 2005:

setlocalset RPSeq=Nfor /f "Tokens=*" %%a in ('enumRP^|FIND "2005 01 20"') do ( call :erp %%a)if "%RPSeq%" EQU "N" goto noneRstRP %RPSeq%endlocalgoto :EOF:none@echo No Restore Points found.endlocalgoto :EOF:erpset RPSeq=%1

NOTE: See the following tips:

How can I create a Restore Point in Windows XP, from the command-line, or from a batch?
How can I retrieve all the available Restore Points on a Windows XP Professional computer?
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?

RstRP.bat contains:

@echo offif {%1}=={} @echo Syntax: RstRP RPSeqNumb&goto :EOFsetlocalset RPSEQ=%1set RstRPVBS="%TEMP%RstRP_%RANDOM%.VBS"set OK=N@echo Set objArgument = Wscript.Arguments>%RstRPVBS%@echo RpSeq = objArgument(0)>>%RstRPVBS%@echo Set obj = GetObject("winmgmts:{impersonationLevel=impersonate}!root/default:SystemRestore")>>%RstRPVBS%@echo if obj.Restore(RpSeq) ^ 0 Then>>%RstRPVBS%@echo     wscript.Echo "N">>%RstRPVBS%@echo else>>%RstRPVBS%@echo     wscript.Echo "Y">>%RstRPVBS%@echo End If>>%RstRPVBS%for /f "Tokens=*" %%s in ('cscript //nologo %RstRPVBS% %RPSEQ%') do ( set OK=%%s)del /q %RstRPVBS%if "%OK%" EQU "Y" shutdown -r -t 01endlocal



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