Non-Task Scheduler Batch File Run at Specific Time

Page 1 of 2 12 LastLast

  1. Posts : 526
    Windows 10 (22H2)
       #1

    Non-Task Scheduler Batch File Run at Specific Time


    If possible, I suppose this will require 2 batch files. One that runs at PC power on (Batch1) that calls the batch file with the desired operation (Batch2). Batch1 is the one I need help with, iow, what code would it contain to run Batch2 at 18:00?
      My Computer


  2. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #2

    Hello @MourningStar,

    MourningStar said:
    If possible, I suppose this will require 2 batch files. One that runs at PC power on (Batch1) that calls the batch file with the desired operation (Batch2).
    As a start, Batch 1 [ which Calls Batch 2 ] will need to go in the Startup folder.

    Type explorer shell:Startup into a cmd prompt and press Enter to go to the actual folder.

    I hope this helps.
      My Computer


  3. Posts : 526
    Windows 10 (22H2)
    Thread Starter
       #3

    ^
    thank you Paul for the reply. However, I am requesting the content of Batch1, i.e. "Batch1 is the one I need help with, iow, what code would it contain to run Batch2 at 18:00?"
      My Computer


  4. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #4

    It might help if you can explain it in a bit more detail.

    Is there a specific reason that you do NOT want to use Task Scheduler [ easier option ] for this?

    Anyway, I did some research for you and found this which might help . . .

    > Schedule a Batch (.bat) File to Run Without Task Scheduler

    Also, have a look [ search ] on StackOverflow as there are MANY posts that might be relative.
      My Computer


  5. Posts : 456
    Windows 10
       #5

    Is batch one going to stay open until the right time?

    Code:
    if "%time:~0,5%"=="18:00" start "" "batch02.bat"
      My Computer


  6. Posts : 526
    Windows 10 (22H2)
    Thread Starter
       #6

    Paul Black said:
    It might help if you can explain it in a bit more detail.
    not sure how much more detail you seek. I thought it was as simple as I could make it.
    Paul Black said:
    Is there a specific reason that you do NOT want to use Task Scheduler [ easier option ] for this?
    Suppose I shut off my computer at 17:45 and power back on at, say, 21:00. Will the Task Scheduler still run the file that was scheduled to run at 18:00?
      My Computer


  7. Posts : 526
    Windows 10 (22H2)
    Thread Starter
       #7

    ricardobohner said:
    Is batch one going to stay open until the right time?
    If the computer is running when "the right time" transpires is the question relevant? IOW, it is possible I fire up the pc at 06:00, shut it down at 11:00 and fire it back up at 14:14 and leave it on until 23:15.
      My Computer


  8. Posts : 526
    Windows 10 (22H2)
    Thread Starter
       #8

    ricardobohner - per your post ...

    Bat1.bat code :
    if "%time:~0,5%"=="16:05" start "" "D:\PredatorOrion\PwrApps\MoonOn.bat"

    MoonOn.bat code :
    "C:\Program Files\Rainmeter\Rainmeter.exe" !DeactivateConfig "BasicDualTemperature"
    "C:\Program Files\Rainmeter\Rainmeter.exe" !ActivateConfig "BasicDualTemperature" "MoonPhase.ini"

    (MoonOn code functions, fyi)

    For test I run Bat1.bat at 16:00. Nothing happened at 16:05
      My Computer


  9. Posts : 456
    Windows 10
       #9

    @MourningStar: Can you test again by putting a pause in MoonOn.bat....maybe the bat starts but closes again "too fast to see" or maybe there is an error, the pause should go at the end of the commands...
      My Computer


  10. Posts : 1,223
    W10-Pro 22H2
       #10

    MourningStar said:
    Bat1.bat code :
    if "%time:~0,5%"=="16:05" start "" "D:\PredatorOrion\PwrApps\MoonOn.bat"

    MoonOn.bat code :
    "C:\Program Files\Rainmeter\Rainmeter.exe" !DeactivateConfig "BasicDualTemperature"
    "C:\Program Files\Rainmeter\Rainmeter.exe" !ActivateConfig "BasicDualTemperature" "MoonPhase.ini"

    For test I run Bat1.bat at 16:00. Nothing happened at 16:05
    I may be missing something here: when bat1 runs, it surely just exits when complete, and will only (by chance) trigger moonon if it happens to run at 16:05 ? You need a batch file that keeps running until the time is right. There seem to be many ways to do this, involving checking the time and looping back, but a simple solution might be to use the 'timeout' batch command: I created this mickey-mouse thing to try it:
    Code:
    timeout /t 10 /nobreak
    echo finished at %time% >> out.txt
    When that runs, it waits 10 sec and then appends a line to out.txt so I can tell it worked. So all you have to do (!) is test the time when this batch file runs, do some arithmetic to convert the required time for moonon to run into a duration from 'now', then pass that as the parameter to timeout (it can apparently handle up to 99,999 seconds). You don't need moonon to be a separate batch file, it can be inside the timer one.

    I tested this, as I had no idea how much CPU activity would be involved in waiting for the timeout - the answer is almost nothing. I created a shortcut to my batch file, and set it to run minimised, so it did not create a window on screen.

    hth, Martin (who had no idea before having a go, so I've learned something)
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 15:25.
Find Us




Windows 10 Forums