Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

Windows Task Scheduler (.BAT)

Windows batch script. Meets all challenge requirements.

As far as I can see this is the only Windows solution so far that meets all requirements and has no nonstandard dependencies (my other solution is similar but requires compilation).

@ECHO OFF SETLOCAL schtasks /Delete /TN RestarterCL /F ECHO Close this window now to stop. TIMEOUT /T 5 FOR /f "tokens=1-2 delims=: " %%a IN ("%TIME%") DO SET /A now=%%a*60+%%b SET /A start=%now%+1 SET /A starth=100+(%start%/60)%%24 SET /A startm=100+%start%%%60 SET /A end=%now%+3 SET /A endh=100+(%end%/60)%%24 SET /A endm=100+%end%%%60 schtasks /Create /SC ONCE /TN RestarterCL /RI 1 /ST %starth:~1,2%:%startm:~1,2% /ET %endh:~1,2%:%endm:~1,2% /IT /Z /F /TR "%~dpnx0" ENDLOCAL 

Program behaves similarly to my C++/COM answermy C++/COM answer.

Program will start and register a one-time task with the Windows task scheduler to start itself up to 60 seconds later (Control Panel -> Administrative Tools -> Task Scheduler to view, task is named "Restarter"). Program will pause for 5 seconds to give you a chance to kill it before it creates the task.

Makes use of command line Task Scheduler interface schtasks.exe. Arithmetic in script is to compute time offsets while keeping the time valid and in HH:MM format.

Challenge Requirements:

  • Starts itself again when finishes. Yes. Task is scheduled just prior to program exit.

  • No more than one instance of the program running at same time. Yes. Program exits fully and does not run for ~60 seconds. It is started by the scheduler.

  • You can ignore any instance that is manually started by user during your cycle. Yes, as a side-effect of using a constant task name.

  • As long as it is guaranteed that it starts again. Yes, provided that Task Scheduler is running and schtasks.exe is present (both true in default Windows configurations).

  • The only way to stop the cycle is to kill the process. Yes, the process can be killed during the 5 second window while it is running. The program deletes the task prior to the 5 second delay, killing it at this time will not leave a stray task in the scheduler.

  • Your solution should not involve restarting of the environment Yes.

Note: Due to limited command line interface, restart time must be specified in minutes and the task will not restart on laptops without the AC adapter plugged in (sorry).

Windows Task Scheduler (.BAT)

Windows batch script. Meets all challenge requirements.

As far as I can see this is the only Windows solution so far that meets all requirements and has no nonstandard dependencies (my other solution is similar but requires compilation).

@ECHO OFF SETLOCAL schtasks /Delete /TN RestarterCL /F ECHO Close this window now to stop. TIMEOUT /T 5 FOR /f "tokens=1-2 delims=: " %%a IN ("%TIME%") DO SET /A now=%%a*60+%%b SET /A start=%now%+1 SET /A starth=100+(%start%/60)%%24 SET /A startm=100+%start%%%60 SET /A end=%now%+3 SET /A endh=100+(%end%/60)%%24 SET /A endm=100+%end%%%60 schtasks /Create /SC ONCE /TN RestarterCL /RI 1 /ST %starth:~1,2%:%startm:~1,2% /ET %endh:~1,2%:%endm:~1,2% /IT /Z /F /TR "%~dpnx0" ENDLOCAL 

Program behaves similarly to my C++/COM answer.

Program will start and register a one-time task with the Windows task scheduler to start itself up to 60 seconds later (Control Panel -> Administrative Tools -> Task Scheduler to view, task is named "Restarter"). Program will pause for 5 seconds to give you a chance to kill it before it creates the task.

Makes use of command line Task Scheduler interface schtasks.exe. Arithmetic in script is to compute time offsets while keeping the time valid and in HH:MM format.

Challenge Requirements:

  • Starts itself again when finishes. Yes. Task is scheduled just prior to program exit.

  • No more than one instance of the program running at same time. Yes. Program exits fully and does not run for ~60 seconds. It is started by the scheduler.

  • You can ignore any instance that is manually started by user during your cycle. Yes, as a side-effect of using a constant task name.

  • As long as it is guaranteed that it starts again. Yes, provided that Task Scheduler is running and schtasks.exe is present (both true in default Windows configurations).

  • The only way to stop the cycle is to kill the process. Yes, the process can be killed during the 5 second window while it is running. The program deletes the task prior to the 5 second delay, killing it at this time will not leave a stray task in the scheduler.

  • Your solution should not involve restarting of the environment Yes.

Note: Due to limited command line interface, restart time must be specified in minutes and the task will not restart on laptops without the AC adapter plugged in (sorry).

Windows Task Scheduler (.BAT)

Windows batch script. Meets all challenge requirements.

As far as I can see this is the only Windows solution so far that meets all requirements and has no nonstandard dependencies (my other solution is similar but requires compilation).

@ECHO OFF SETLOCAL schtasks /Delete /TN RestarterCL /F ECHO Close this window now to stop. TIMEOUT /T 5 FOR /f "tokens=1-2 delims=: " %%a IN ("%TIME%") DO SET /A now=%%a*60+%%b SET /A start=%now%+1 SET /A starth=100+(%start%/60)%%24 SET /A startm=100+%start%%%60 SET /A end=%now%+3 SET /A endh=100+(%end%/60)%%24 SET /A endm=100+%end%%%60 schtasks /Create /SC ONCE /TN RestarterCL /RI 1 /ST %starth:~1,2%:%startm:~1,2% /ET %endh:~1,2%:%endm:~1,2% /IT /Z /F /TR "%~dpnx0" ENDLOCAL 

Program behaves similarly to my C++/COM answer.

Program will start and register a one-time task with the Windows task scheduler to start itself up to 60 seconds later (Control Panel -> Administrative Tools -> Task Scheduler to view, task is named "Restarter"). Program will pause for 5 seconds to give you a chance to kill it before it creates the task.

Makes use of command line Task Scheduler interface schtasks.exe. Arithmetic in script is to compute time offsets while keeping the time valid and in HH:MM format.

Challenge Requirements:

  • Starts itself again when finishes. Yes. Task is scheduled just prior to program exit.

  • No more than one instance of the program running at same time. Yes. Program exits fully and does not run for ~60 seconds. It is started by the scheduler.

  • You can ignore any instance that is manually started by user during your cycle. Yes, as a side-effect of using a constant task name.

  • As long as it is guaranteed that it starts again. Yes, provided that Task Scheduler is running and schtasks.exe is present (both true in default Windows configurations).

  • The only way to stop the cycle is to kill the process. Yes, the process can be killed during the 5 second window while it is running. The program deletes the task prior to the 5 second delay, killing it at this time will not leave a stray task in the scheduler.

  • Your solution should not involve restarting of the environment Yes.

Note: Due to limited command line interface, restart time must be specified in minutes and the task will not restart on laptops without the AC adapter plugged in (sorry).

added 185 characters in body
Source Link
Jason C
  • 6.5k
  • 2
  • 22
  • 33

Windows Task Scheduler (.BAT)

Windows batch script. Meets all challenge requirements.

As far as I can see this is the only Windows solution so far that meets all requirements and has no nonstandard dependencies (my other solution is similar but requires compilation).

@ECHO OFF SETLOCAL schtasks /Delete /TN RestarterCL /F ECHO Close this window now to stop. TIMEOUT /T 5 FOR /f "tokens=1-2 delims=: " %%a IN ("%TIME%") DO SET /A now=%%a*60+%%b SET /A start=%now%+1 SET /A starth=100+(%start%/60)%%24 SET /A startm=100+%start%%%60 SET /A end=%now%+3 SET /A endh=100+(%end%/60)%%24 SET /A endm=100+%end%%%60 schtasks /Create /SC ONCE /TN RestarterCL /RI 1 /ST %starth:~1,2%:%startm:~1,2% /ET %endh:~1,2%:%endm:~1,2% /IT /Z /F /TR "%~dpnx0" ENDLOCAL 

Program behaves similarly to my C++/COM answer.

Program will start and register a one-time task with the Windows task scheduler to start itself up to 60 seconds later (Control Panel -> Administrative Tools -> Task Scheduler to view, task is named "Restarter"). Program will pause for 5 seconds to give you a chance to kill it before it creates the task.

Makes use of command line Task Scheduler interface schtasks.exe. Arithmetic in script is to compute time offsets while keeping the time valid and in HH:MM format.

Challenge Requirements:

  • Starts itself again when finishes. Yes. Task is scheduled just prior to program exit.

  • No more than one instance of the program running at same time. Yes. Program exits fully and does not run for ~60 seconds. It is started by the scheduler.

  • You can ignore any instance that is manually started by user during your cycle. Yes, as a side-effect of using a constant task name.

  • As long as it is guaranteed that it starts again. Yes, provided that Task Scheduler is running and schtasks.exe is present (both true in default Windows configurations).

  • The only way to stop the cycle is to kill the process. Yes, the process can be killed during the 5 second window while it is running. The program deletes the task prior to the 5 second delay, killing it at this time will not leave a stray task in the scheduler.

  • Your solution should not involve restarting of the environment Yes.

Note: Due to limited command line interface, restart time must be specified in minutes and the task will not restart on laptops without the AC adapter plugged in (sorry).

Windows Task Scheduler (.BAT)

Windows batch script. Meets all challenge requirements.

@ECHO OFF SETLOCAL schtasks /Delete /TN RestarterCL /F ECHO Close this window now to stop. TIMEOUT /T 5 FOR /f "tokens=1-2 delims=: " %%a IN ("%TIME%") DO SET /A now=%%a*60+%%b SET /A start=%now%+1 SET /A starth=100+(%start%/60)%%24 SET /A startm=100+%start%%%60 SET /A end=%now%+3 SET /A endh=100+(%end%/60)%%24 SET /A endm=100+%end%%%60 schtasks /Create /SC ONCE /TN RestarterCL /RI 1 /ST %starth:~1,2%:%startm:~1,2% /ET %endh:~1,2%:%endm:~1,2% /IT /Z /F /TR "%~dpnx0" ENDLOCAL 

Program behaves similarly to my C++/COM answer.

Program will start and register a one-time task with the Windows task scheduler to start itself up to 60 seconds later (Control Panel -> Administrative Tools -> Task Scheduler to view, task is named "Restarter"). Program will pause for 5 seconds to give you a chance to kill it before it creates the task.

Makes use of command line Task Scheduler interface schtasks.exe. Arithmetic in script is to compute time offsets while keeping the time valid and in HH:MM format.

Challenge Requirements:

  • Starts itself again when finishes. Yes. Task is scheduled just prior to program exit.

  • No more than one instance of the program running at same time. Yes. Program exits fully and does not run for ~60 seconds. It is started by the scheduler.

  • You can ignore any instance that is manually started by user during your cycle. Yes, as a side-effect of using a constant task name.

  • As long as it is guaranteed that it starts again. Yes, provided that Task Scheduler is running and schtasks.exe is present (both true in default Windows configurations).

  • The only way to stop the cycle is to kill the process. Yes, the process can be killed during the 5 second window while it is running. The program deletes the task prior to the 5 second delay, killing it at this time will not leave a stray task in the scheduler.

  • Your solution should not involve restarting of the environment Yes.

Note: Due to limited command line interface, restart time must be specified in minutes and the task will not restart on laptops without the AC adapter plugged in (sorry).

Windows Task Scheduler (.BAT)

Windows batch script. Meets all challenge requirements.

As far as I can see this is the only Windows solution so far that meets all requirements and has no nonstandard dependencies (my other solution is similar but requires compilation).

@ECHO OFF SETLOCAL schtasks /Delete /TN RestarterCL /F ECHO Close this window now to stop. TIMEOUT /T 5 FOR /f "tokens=1-2 delims=: " %%a IN ("%TIME%") DO SET /A now=%%a*60+%%b SET /A start=%now%+1 SET /A starth=100+(%start%/60)%%24 SET /A startm=100+%start%%%60 SET /A end=%now%+3 SET /A endh=100+(%end%/60)%%24 SET /A endm=100+%end%%%60 schtasks /Create /SC ONCE /TN RestarterCL /RI 1 /ST %starth:~1,2%:%startm:~1,2% /ET %endh:~1,2%:%endm:~1,2% /IT /Z /F /TR "%~dpnx0" ENDLOCAL 

Program behaves similarly to my C++/COM answer.

Program will start and register a one-time task with the Windows task scheduler to start itself up to 60 seconds later (Control Panel -> Administrative Tools -> Task Scheduler to view, task is named "Restarter"). Program will pause for 5 seconds to give you a chance to kill it before it creates the task.

Makes use of command line Task Scheduler interface schtasks.exe. Arithmetic in script is to compute time offsets while keeping the time valid and in HH:MM format.

Challenge Requirements:

  • Starts itself again when finishes. Yes. Task is scheduled just prior to program exit.

  • No more than one instance of the program running at same time. Yes. Program exits fully and does not run for ~60 seconds. It is started by the scheduler.

  • You can ignore any instance that is manually started by user during your cycle. Yes, as a side-effect of using a constant task name.

  • As long as it is guaranteed that it starts again. Yes, provided that Task Scheduler is running and schtasks.exe is present (both true in default Windows configurations).

  • The only way to stop the cycle is to kill the process. Yes, the process can be killed during the 5 second window while it is running. The program deletes the task prior to the 5 second delay, killing it at this time will not leave a stray task in the scheduler.

  • Your solution should not involve restarting of the environment Yes.

Note: Due to limited command line interface, restart time must be specified in minutes and the task will not restart on laptops without the AC adapter plugged in (sorry).

added 2 characters in body
Source Link
Jason C
  • 6.5k
  • 2
  • 22
  • 33

Windows Task Scheduler (.BAT)

Windows batch script. Meets all challenge requirements.

@ECHO OFF SETLOCAL schtasks /Delete /TN RestarterCL /F ECHO Close this window now to stop. TIMEOUT /T 5 FOR /f "tokens=1-2 delims=: " %%a IN ("%TIME%") DO SET /A now=%%a*60+%%b SET /A start=%now%+1 SET /A starth=100+(%start%/60)%%24 SET /A startm=100+%start%%%60 SET /A end=%now%+3 SET /A endh=100+(%end%/60)%%24 SET /A endm=100+%end%%%60 schtasks /Create /SC ONCE /TN RestarterCL /RI 1 /ST %starth:~1,2%:%startm:~1,2% /ET %endh:~1,2%:%endm:~1,2% /IT /Z /F /TR "%~dpnx0" ENDLOCAL 

Program behaves similarly to my C++/COM answer.

Program will start and register a one-time task with the Windows task scheduler to start itself up to 60 seconds later (Control Panel -> Administrative Tools -> Task Scheduler to view, task is named "Restarter"). Program will pause for 5 seconds to give you a chance to kill it before it creates the task.

Makes use of command line Task Scheduler interface schtasks.exe. Arithmetic in script is to compute time offsets while keeping the time valid and in HH:MM format.

Challenge Requirements:

  • Starts itself again when finishes. Yes. Task is scheduled just prior to program exit.

  • No more than one instance of the program running at same time. Yes. Program exits fully and does not run for 5~60 seconds. It is started by the scheduler.

  • You can ignore any instance that is manually started by user during your cycle. Yes, as a side-effect of using a constant task name.

  • As long as it is guaranteed that it starts again. Yes, provided that Task Scheduler is running and schtasks.exe is present (both true in default Windows configurations).

  • The only way to stop the cycle is to kill the process. Yes, the process can be killed during the 5 second window while it is running. The program deletes the task prior to the 5 second delay, killing it at this time will not leave a stray task in the scheduler.

  • Your solution should not involve restarting of the environment Yes.

Note: Due to limited command line interface, restart time must be specified in minutes and the task will not restart on laptops without the AC adapter plugged in (sorry).

Windows Task Scheduler (.BAT)

Windows batch script. Meets all challenge requirements.

@ECHO OFF SETLOCAL schtasks /Delete /TN RestarterCL /F ECHO Close this window now to stop. TIMEOUT /T 5 FOR /f "tokens=1-2 delims=: " %%a IN ("%TIME%") DO SET /A now=%%a*60+%%b SET /A start=%now%+1 SET /A starth=100+(%start%/60)%%24 SET /A startm=100+%start%%%60 SET /A end=%now%+3 SET /A endh=100+(%end%/60)%%24 SET /A endm=100+%end%%%60 schtasks /Create /SC ONCE /TN RestarterCL /RI 1 /ST %starth:~1,2%:%startm:~1,2% /ET %endh:~1,2%:%endm:~1,2% /IT /Z /F /TR "%~dpnx0" ENDLOCAL 

Program behaves similarly to my C++/COM answer.

Program will start and register a one-time task with the Windows task scheduler to start itself up to 60 seconds later (Control Panel -> Administrative Tools -> Task Scheduler to view, task is named "Restarter"). Program will pause for 5 seconds to give you a chance to kill it before it creates the task.

Makes use of command line Task Scheduler interface schtasks.exe. Arithmetic in script is to compute time offsets while keeping the time valid and in HH:MM format.

Challenge Requirements:

  • Starts itself again when finishes. Yes. Task is scheduled just prior to program exit.

  • No more than one instance of the program running at same time. Yes. Program exits fully and does not run for 5 seconds. It is started by the scheduler.

  • You can ignore any instance that is manually started by user during your cycle. Yes, as a side-effect of using a constant task name.

  • As long as it is guaranteed that it starts again. Yes, provided that Task Scheduler is running and schtasks.exe is present (both true in default Windows configurations).

  • The only way to stop the cycle is to kill the process. Yes, the process can be killed during the 5 second window while it is running. The program deletes the task prior to the 5 second delay, killing it at this time will not leave a stray task in the scheduler.

  • Your solution should not involve restarting of the environment Yes.

Note: Due to limited command line interface, restart time must be specified in minutes and the task will not restart on laptops without the AC adapter plugged in (sorry).

Windows Task Scheduler (.BAT)

Windows batch script. Meets all challenge requirements.

@ECHO OFF SETLOCAL schtasks /Delete /TN RestarterCL /F ECHO Close this window now to stop. TIMEOUT /T 5 FOR /f "tokens=1-2 delims=: " %%a IN ("%TIME%") DO SET /A now=%%a*60+%%b SET /A start=%now%+1 SET /A starth=100+(%start%/60)%%24 SET /A startm=100+%start%%%60 SET /A end=%now%+3 SET /A endh=100+(%end%/60)%%24 SET /A endm=100+%end%%%60 schtasks /Create /SC ONCE /TN RestarterCL /RI 1 /ST %starth:~1,2%:%startm:~1,2% /ET %endh:~1,2%:%endm:~1,2% /IT /Z /F /TR "%~dpnx0" ENDLOCAL 

Program behaves similarly to my C++/COM answer.

Program will start and register a one-time task with the Windows task scheduler to start itself up to 60 seconds later (Control Panel -> Administrative Tools -> Task Scheduler to view, task is named "Restarter"). Program will pause for 5 seconds to give you a chance to kill it before it creates the task.

Makes use of command line Task Scheduler interface schtasks.exe. Arithmetic in script is to compute time offsets while keeping the time valid and in HH:MM format.

Challenge Requirements:

  • Starts itself again when finishes. Yes. Task is scheduled just prior to program exit.

  • No more than one instance of the program running at same time. Yes. Program exits fully and does not run for ~60 seconds. It is started by the scheduler.

  • You can ignore any instance that is manually started by user during your cycle. Yes, as a side-effect of using a constant task name.

  • As long as it is guaranteed that it starts again. Yes, provided that Task Scheduler is running and schtasks.exe is present (both true in default Windows configurations).

  • The only way to stop the cycle is to kill the process. Yes, the process can be killed during the 5 second window while it is running. The program deletes the task prior to the 5 second delay, killing it at this time will not leave a stray task in the scheduler.

  • Your solution should not involve restarting of the environment Yes.

Note: Due to limited command line interface, restart time must be specified in minutes and the task will not restart on laptops without the AC adapter plugged in (sorry).

Source Link
Jason C
  • 6.5k
  • 2
  • 22
  • 33
Loading