hans
hans

Reputation: 41

Reboot & continue batch script

Below is the script created for increasing the swaps & mounting the driver. Now in this script I want to add the feature that after setting the page file the system will be rebooted & once reboot is done, it will resume with next step which is mounting driver. Can you please help in this.

@echo off

wmic pagefileset create name="D:\pagefile.sys"

wmic pagefileset where name="D:\\pagefile.sys" set InitialSize=20480,MaximumSize=25480

echo "Pagefile created. 

Need to add script to reboot the windows & after reboot continue with next step


DISKPART /s C:\Users\Desktop\param_files\instructions.txt
echo "Drive mounted successfully"

Regards

Upvotes: 0

Views: 5160

Answers (1)

dcg
dcg

Reputation: 4219

You could mark where you want to restart your script like:

@echo off

REM Initialization here

if "%~1" neq "" goto :%~1

REM Do some stuff1 here
call :markReboot stuff2

REM Making sure to not execute some part of stuff2 before rebooting
goto :eof 

:stuff2
REM Do some stuff2 here
call :markReboot stuff3
goto :eof

REM ...

:stuffn
REM Do some stuffn here
goto :eof

:markReboot
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce /t REG_SZ /d "\"%~dpf0\" %~1" /v  RestartMyScript /f 
shutdown /r /t 0

NOTE: The /f is not really needed in the reg add command.

EDIT: Adapting my answer to your specific should look like:

@echo off

if "%~1" neq "" goto :%~1

wmic pagefileset create name="D:\pagefile.sys"
wmic pagefileset where name="D:\\pagefile.sys" set InitialSize=20480,MaximumSize=25480
echo "Pagefile created. 

call :markReboot stuff2
goto :eof

:stuff2
DISKPART /s C:\Users\Desktop\param_files\instructions.txt
echo "Drive mounted successfully"
goto :eof

:markReboot
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce /t REG_SZ /d "\"%~dpf0\" %~1" /v  RestartMyScript /f 
shutdown /r /t 0

Upvotes: 1

Related Questions