Resume batch script after reboot
Solution 1:
One way would be to create a registry key HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\
by pointing to script to run on startup.
The scenario would be:
script01.bat does his job and write HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\ with value "path to script02.bat"
script02.bat does his job and write HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\ with value "path to script03.bat" and so long.
Solution 2:
This script is a very good solution! I tried it and can confirm it works!
However I'd recommend changing %~n0
and %~dpnx0
to "%~n0"
and "%~dpnx0"
to prevent Regedit Syntax errors.
@echo off
call :Resume
goto %current%
goto :eof
:one
::Add script to Run key
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v %~n0 /d %~dpnx0 /f
echo two >%~dp0current.txt
echo -- Section one --
pause
shutdown -r -t 0
goto :eof
:two
echo three >%~dp0current.txt
echo -- Section two --
pause
shutdown -r -t 0
goto :eof
:three
::Remove script from Run key
reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v %~n0 /f
del %~dp0current.txt
echo -- Section three --
pause
goto :eof
:resume
if exist %~dp0current.txt (
set /p current=<%~dp0current.txt
) else (
set current=one
)
Solution 3:
Look at BoxStarter. http://boxstarter.org
This should get you what you need for reboot and continue.
Solution 4:
Sorry for the late answer. Couldn't it be achieved with scheduled tasks ? Like create a scheduled task that runs once after reboot and launches the script where you want to resume it ?