• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1744
  • Last Modified:

Running continuously cmd line script commands after restart

Hello,

I've got cmd script. Some of its commands demand restart. I need to continue its execution after the restart at the point it interrupted.

Is there way to do it other than putting RunOnce registry key and therefore splitting one cmd file into several parts?

Thanks
Shabby
0
school1282
Asked:
school1282
2 Solutions
 
dovcampCommented:
In theory you could run the command from RunOnce (or taskmanager) then after the first action takes place that requires a reboot write out some sort of file to the system (using copy con).  After the system reboots and the script runs again, it should check to see if this first file is present (If exists) and if so it will skip to the next task.  Repeat as needed.  
0
 
boris711Commented:
Are you using VBScript, or similar? If so, you could write your script file to write a text file to keep track of the progress of your script.

Non-Technical Overview:

Script runs,
if <text file> doesn't exist, then run first process(es)
    then write file with progress value, reboot  
elseif <text file> does exist
    then read file value, go to appropriate part of script based on value to continue processes
end if

at end of script delete file and reg key.

Hope this helps.
 
0
 
canaliCommented:
Another way to start a process  is  "Scheduled Tasks" choosing the option "When my computer starts"

you can put this batch in the "scheduled tasks" and go
example of batch script

@echo off
if exist *.goto (
     for /f %%i in ('dir /w /b *.goto') do  goto :%%i
) else (
     echo For starting the job chain
     echo you need to create th file FASE1.goto
     echo EX:   echo. ^> FASE1.goto
)    


goto :end

rem ------------------------3 jobs parts--------------------
:FASE1.goto
  echo FASE 1
  Rem your code
 
  del *.goto
  echo. >FASE2.goto
  rem shutdown /r
goto :end
:FASE2.goto
  echo FASE 2
  Rem your code

  del *.goto
  echo. >FASE3.goto
  rem shutdown /r
goto :end
:FASE3.goto
  echo FASE 3
  Rem your code

  del *.goto
  rem ---- stop the execution chain -----
  echo. >END.goto
goto :end

:END.goto
  echo job chain finished!


:end
0
 
school1282Author Commented:
Thank you canali , but this way I'll be forced to add task scheduling to my unattended installation.
So far, solution of boris711 is most acceptable, which is  accually suggestion of dovcamp .
0
 
canaliCommented:
you should put the my batch:
in HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
The sample is divided in 3 phases but you can extend the script as you need
when phase3 is reached every time you reboot script starts but only print "job chain finished!"
for extend
:FASE3.goto
  echo FASE 3
  Rem appropriate part of script based on value to continue processes

  del *.goto
  echo. >step4.goto
goto :end
:step4.goto
 echo step4
  Rem appropriate part of script based on value to continue processes

  del *.goto
  echo. >end.goto
  rem echo.>end.goto -----------------stop the process
goto :end
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now