Page 1 of 1

timed batch file execution

Posted: 09 Dec 2017 05:46
by joe
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

Re: timed batch file execution

Posted: 09 Dec 2017 07:48
by aGerman
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

Re: timed batch file execution

Posted: 09 Dec 2017 10:40
by Squashman
You need some type of scheduling daemon or service. Not sure how you think this can be done otherwise.

Re: timed batch file execution

Posted: 09 Dec 2017 14:01
by miskox
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

Re: timed batch file execution

Posted: 09 Dec 2017 14:02
by ShadowThief
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.)

Re: timed batch file execution

Posted: 09 Dec 2017 18:00
by einstein1969
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

Re: timed batch file execution

Posted: 12 Dec 2017 15:57
by pieh-ejdsch
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

Re: timed batch file execution

Posted: 16 Mar 2018 22:50
by Samir
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

Re: timed batch file execution

Posted: 17 Mar 2018 11:50
by Squashman
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.

Re: timed batch file execution

Posted: 17 Mar 2018 15:36
by Samir
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:

Re: timed batch file execution

Posted: 17 Mar 2018 17:39
by Compo
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.

Re: timed batch file execution

Posted: 25 Mar 2018 17:48
by Ed Dyreen
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 ! -->