重启&继续批处理脚本

时间:2017-08-10 20:41:12

标签: windows batch-file

以下是为增加互换而创建的脚本。安装驱动程序。现在在这个脚本中,我想添加一个功能,在设置页面文件后,系统将重新启动&一旦重启完成,它将继续下一步安装驱动程序。你能帮忙吗?

@echo off

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

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

echo "Pagefile created. 

需要添加脚本来重新启动Windows&重启后继续下一步

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

此致

1 个答案:

答案 0 :(得分:0)

您可以标记要重新启动脚本的位置,如:

@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

注意: /f命令中并不真正需要reg add

编辑:根据您的具体情况调整我的答案应该如下:

@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