Non-Task Scheduler Batch File Run at Specific Time

Page 2 of 2 FirstFirst 12

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

    Hello @MourningStar,

    Unless I am missing something, why do you need TWO Scripts?

    Is there a reason you can NOT put just one Script in the . . .

    > %UserProfile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

    . . . directory [ that obviously opens at Startup ] using Loop to cycle over and check the time, and then when the time is right, run the MoonOn commands?

    MourningStar said:
    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?
    The Task Scheduler will run the task whenever it is set to do so.

    If your computer is shut off, it will NOT be able to run the Script anyway !

    Have you looked at? . . .

    > How to Enable or Disable Scheduled Task in Windows 10
    > How to Create Task to Run App or Script at Logon in Windows 10

    I assume that the program is this one? . . .

    > Rainmeter
    > Rainmeter - Manual
    Last edited by Paul Black; 04 Jul 2022 at 06:39.
      My Computer


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

    Hello @MourningStar,

    What about something like this for Batch_1.bat? . . .

    Code:
    
    set Hour=%time:~0,2%
    set Batch_2_Run=True
    
    if %Hour% geq 18 set Batch_2_Run=False
    if %Hour% leq 17 set Batch_2_Run=False
    
    if "%Batch_2_Run%"=="True" (
        CALL "Batch_2_Run_Path.bat"
    )
      My Computer


  3. Posts : 3,274
    Win10
       #13

    The Task Schedule has a Settings Tab, where one can select "Run task as soon as possible after a scheduled start is missed", which ought to work if the Target Time has already passed on Startup (although I haven't tested it fully - so can't be 100% sure).

    As for the timer batch file, following some of Paul's suggestions, something like this all-in-one batch file could work.

    It will keep running and check the time in a loop , and at the designated time (or ~10 sec thereafter as set by the timeout /t command), it will trigger the second set of CALL commands and exit - and if the Target time has already passed when it is started on Startup, it will trigger the second set of commands immediately and exit.

    All-in-one-Timer.bat (note: Set the Target Time as indicated).
    Code:
    @echo off
    SetLocal
    
    :: Set the Target Time here, as HoursMinsSeconds eg 18:30:00 as 183000
    :: Set it in "6" digit HourMinSec format eg as shown above or if less than 10:00:00, then for eg 093030 with the lead zero.
    
    SET   TargetTime=140624
    echo.
    echo. TargetTime for second part of the Batch file is set to %TargetTime%
    echo.
    
    :Loop
    SET    CurrentTime=%time:~0,8%
    SET    CurrentTime=%CurrentTime: =0%
    SET    CurrentTime=%CurrentTime::=%
    echo.  TargetTime  is  %TargetTime%
    echo.  CurrentTime is  %CurrentTime%
    echo.
    
    SET Action=True
    IF %CurrentTime% gtr %TargetTime% SET Action=True
    IF %CurrentTime% lss %TargetTime% SET Action=False
    IF "%Action%"=="True" (
        echo.=========================================================================
        echo.Now Running the second section which has target commands
        echo.=========================================================================
        CALL :SecondPart && Goto :EOF
    )
    timeout /t 10 /nobreak
    GoTo :Loop
    
    :EOF
    ::====================== section with some example target commands ===============================::
    
    :SecondPart
    
    Dir C:\Windows\*.exe
    Dir C:\Windows\*.ini
    pause
    pause
    exit /B
    
    ::================================================================================================::
    :: ref: https://stackoverflow.com/questions/55227816/run-a-batch-file-between-specific-time-in-a-day
    After debugging, all the echo commands can be removed.

    If wanted, instead of making a CALL to the :SecondPart label within the same batch file, you can also make a CALL to a second.bat file.
    Code:
    instead of
    CALL  :SecondPart && Goto :EOF
    use
    CALL  "C:\some path to second.bat" && Goto :EOF
    Hopefully it works.
      My Computers


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

    Yes, the app is a Rainmeter custom skin. However, I do shut off/power on my computer on an as needed basis (a topic already beaten to death so please don't bring it up, thank you). I could have done this in the skin itself and I may go that route. So, if this fact renders the request not feasible, not a problem. Maybe I was thinking too random. My current process (single push of a button) is perhaps the easiest, a programmed key that runs the sun off/moon on script.

    However, all this is still helpful and not fruitless as my web-research revealed many others requesting non-task scheduler time-based batch run solutions. Those I found had no solutions for my case and is why I came here. This topic should help others.

    -thx
      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 06:31.
Find Us




Windows 10 Forums