How to open apps on startup only on a particular time

Solution 1:

Rather than starting Teams on startup, you can write a small script that first checks the time, and then starts the application.

Here's an example PowerShell script. Save it with a .ps1 file extension and place a shortcut to it in your startup folder

# Get the hour in 24h format
[int]$hour = Get-Date -Format "HH"

# Start teams only between 7 and 12 in the morning
if ($hour -gt 7 -and $hour -le 12) 
{
    Start-Process $env:LOCALAPPDATA\Microsoft\Teams\Current\Teams.exe
}

A DOS batch file would look something like this. Note that the %time% variable is culture dependent, so I'm not sure if this works with a 12 hour time format. A better way would be to use wmic to get the time. There are many questions about that already.

for /f "delims=:" %%x in ("%time%") do set hour=%%x

if %hour% GEQ 7 (
    if %hour% LSS 12 (
        %LOCALAPPDATA%\Microsoft\Teams\Current\Teams.exe
    )
)