Running continuously cmd line script commands after restart

Posted on 2006-04-30
Last Modified: 2013-11-18

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?

Question by:school1282
    LVL 4

    Accepted Solution

    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.  
    LVL 1

    Assisted Solution

    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.
    LVL 14

    Expert Comment

    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--------------------
      echo FASE 1
      Rem your code
      del *.goto
      echo. >FASE2.goto
      rem shutdown /r
    goto :end
      echo FASE 2
      Rem your code

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

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

      echo job chain finished!

    LVL 1

    Author Comment

    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 .
    LVL 14

    Expert Comment

    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
      echo FASE 3
      Rem appropriate part of script based on value to continue processes

      del *.goto
      echo. >step4.goto
    goto :end
     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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Suggested Solutions

    Title # Comments Views Activity
    XSL Grouping 7 33
    remove ie 11 and recover ie 10 8 17
    Disabling automatic web page translations 9 25
    use of cookies and regulations 1 30
    Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
    I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now