Answer the question
In order to leave comments, you need to log in
How to start and end a certain program using cmd?
Good afternoon.
There is a task to implement a bat file that, after launching at a specified time (for example, at 16:00), launches a program, after which, at a specified time (say, 17:00), it ends and turns off the computer.
I managed to master this code:
@echo off
chcp 866
setlocal enabledelayedexpansion
echo Параметры запуска:
set /p sh=Час запуска:
set /p sm=Минута запуска:
set /p sp=Путь к программе (в ковычках):
echo Параметры завершения:
set /p eh=Час завершения:
set /p em=Минута завершения
set /p ep=Имя процесса:
:start
set h=!time:~0,2!
set m=!time:~3,2!
if !sh!==!h! (
if !sm!==!m! (
start "" !sp!
goto :finish
)
)
:finish
set h=!time:~0,2!
set m=!time:~3,2!
if !eh!==!h! (
if !em!==!m! (
taskkill /f /im !p!
goto :shutdown
)
)
:shutdown
shutdown -s -t 60
pause
exit
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question