D
D
Denis Davydenko2020-06-26 12:29:17
cmd/bat
Denis Davydenko, 2020-06-26 12:29:17

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


It only works when the program is running. Help me fix it please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2020-06-26
kuzmin @sergueik

TASKKILL - Terminate a process in Windows.
SHUTDOWN - shutdown / restart command
SCHTASKS - command line job management

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question