timed batch file execution

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
joe
Posts: 35
Joined: 06 Sep 2017 07:56

timed batch file execution

#1 Post by joe » 09 Dec 2017 05:46

hi

I need a batch script to start at a particular time everyday (say 9AM) and execute notepad.exe.

iam not interested in using windows task scheduler or any other utility.

any help ??

thanx in advance for sparing me your valuable time

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: timed batch file execution

#2 Post by aGerman » 09 Dec 2017 07:48

iam not interested in using windows task scheduler
Then you are out of luck. SCHTASKS would be for sure the preferred command but it does nothing else but creating a scheduled task.

Steffen

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: timed batch file execution

#3 Post by Squashman » 09 Dec 2017 10:40

You need some type of scheduling daemon or service. Not sure how you think this can be done otherwise.

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: timed batch file execution

#4 Post by miskox » 09 Dec 2017 14:01

You could do something like this:

Code: Select all

:start
if current_time more than 09:00 then notepad.exe
wait 1 minute (or wait 24 hours)
goto start
Saso

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: timed batch file execution

#5 Post by ShadowThief » 09 Dec 2017 14:02

Squashman wrote:
09 Dec 2017 10:40
You need some type of scheduling daemon or service. Not sure how you think this can be done otherwise.
Maybe he's expecting to be able to use an infinite loop and a timeout command. (Don't do that by the way; you'll blow up your processor.)

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: timed batch file execution

#6 Post by einstein1969 » 09 Dec 2017 18:00

miskox wrote:
09 Dec 2017 14:01
You could do something like this:

Code: Select all

:start
if current_time more than 09:00 then notepad.exe
wait 1 minute (or wait 24 hours)
goto start
Saso
this?

Code: Select all

@echo off

:label

   ping 127.0.0.1 -n 2 >nul

   if %time:~0,2% equ 9 if %time:~3,2% equ 0 (
      start notepad.exe
      ping 127.0.0.1 -n 86398 >nul
   )

goto label
einstein1969

pieh-ejdsch
Posts: 240
Joined: 04 Mar 2014 11:14
Location: germany

Re: timed batch file execution

#7 Post by pieh-ejdsch » 12 Dec 2017 15:57

This will only use robocopy to pause this time

Code: Select all

@echo off
echo Start this batch at %time%

 rem Pausiere Programmablauf wenn END Uhr bis begin Uhr
 rem Mindestens zwei Minuten Überbrücken /RH:Ende-Beginn 
 rem Eine Minute vom Beginn abziehen
setlocal

:: /RH:%Ende%-%Beginn%
:: set Beginn is End Time for start - set this Time one minute before -means start for wait ; minute -1
:: set Ende   
:: PauseEnd    -before    this time robocopy not start        ; No Copy -script ends
::             -between             pause and robocopy start  ; Copy    -
::              -when arrived pause END then script starts    ; success
:: PauseBegin  -after               robocopy not start        ; No Copy  

 rem Pause
set begin=0600
set end=0900


set "RC=%temp%\RCtmp.log"
type nul >"%RC%"
robocopy . . " Zeitfenster ."  /RH:%End%-%Begin%  /L /W:1 /R:1 /nFL /nDL /njH /njS /tee /Log:"%RC%" |(
  for /f "tokens=1*" %%a in ('find "..." ^^^<"%RC%"') do @(
    echo Zeit fuer eine Pause %time%
    >&3 echo Zeit fuer eine Pause %time%
    echo Programm wird %%b
    >&3 echo Programm wird %%b
  ) >> D:\Log.txt
) && (
 echo this program will be continued
  rem start programm
 goto :continue
 ) || (
 echo abort batch from  %end:~,2%:%end:~-2% to %begin:~,2%:%begin:~-2% ,Time:%time%
  rem goto :something
)

del "%RC%"
pause
exit /b

:continue
del "%RC%"
echo start program at %time%
pause
 rem ...
Phil

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: timed batch file execution

#8 Post by Samir » 16 Mar 2018 22:50

A little late to the party, but I use this in several batches. It doesn't require anything external except the ping command. It starts the batch at 1am.

Code: Select all

:START
PING -n 60 127.0.0.1 > NUL
SET CURTIME=%TIME:~0,-6%
IF NOT "%CURTIME%"==" 1:00" GOTO START

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: timed batch file execution

#9 Post by Squashman » 17 Mar 2018 11:50

I think you are all missing the intended request. The user said they wanted a batch file to start a particular time of the day. They are not asking to pause execution of a batch file until a specified time of the day.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: timed batch file execution

#10 Post by Samir » 17 Mar 2018 15:36

Squashman wrote:
17 Mar 2018 11:50
I think you are all missing the intended request. The user said they wanted a batch file to start a particular time of the day. They are not asking to pause execution of a batch file until a specified time of the day.
Hmmm...but if the main loop of the batch file won't start until the specified time, isn't that about the same thing? :wink:

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: timed batch file execution

#11 Post by Compo » 17 Mar 2018 17:39

Without scheduled tasks the answers given may be the only option, but I agree with Squashman, they aren't what was asked for.

What was asked for was a batch file which runs at a specific time, not a constantly running batch file.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: timed batch file execution

#12 Post by Ed Dyreen » 25 Mar 2018 17:48

ShadowThief wrote:
09 Dec 2017 14:02
Maybe he's expecting to be able to use an infinite loop and a timeout command. (Don't do that by the way; you'll blow up your processor.)
I disagree, WSH.sleep is good cpu conserving, ping not so much, ping also needs ethernet support or errors out.

Code: Select all

<!-- : Enable embedded WSF comment
@echo off

cScript.EXE //noLogo "me myself &I.WSF" //job:JScript sleep_

goto :skip

:: --------------------------------------------------------------------------------------------------------------------------
:: WSF script ( function, arguments,"" )
:: --------------------------------------------------------------------------------------------------------------------------
:: last updated       : 2015^06^03
:: support            : naDelayed
:: languages          : N/A
::
:: ( disable embedded WSF comment -->
<package>

	<job id="JScript"><script language="JScript">

		if ( WScript.Arguments.length > 0 ) {

			if ( WScript.Arguments(0) == "sleep_" ) {

				var $time;
				//
				if ( WScript.Arguments.length > 1 ) {

					$time = WScript.Arguments(1);

				} else 	$time = 1;

				$time = $time +'000';
				//
				WSH.sleep( $time );
			};
		};

	</script></job>

	<job id="VBScript"><script language="VBScript">

		If WScript.Arguments.length > 0 Then
		rem (
			a vbscript function doing something...
		rem )
		End If

	</script></job>

</package>
<!-- : Enable embedded WSF comment :: )
:: --------------------------------------------------------------------------------------------------------------------------
:skip () disable embedded WSF comment, must be last line in batch ! -->

Post Reply