A
A
Andrey2021-09-05 08:42:11
cmd/bat
Andrey, 2021-09-05 08:42:11

How to kill a given process at a specific time in Windows via CMD?

Tell me how to kill a given process at a specific time in Windows through CMD? For example at 05:00 am.
Windows schedulers are not suitable.
You need something like taskkill for a given time, so that every day at 5 in the morning it kills the process.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
TirkinTir, 2021-09-05
@andrey-marun

With a bit of "cutting". Check the variable ttt in the if statement and write with a space for the time where the hour is displayed with one character.

@echo off

:loop
timeout /t 60 /nobreak
call set ttt=%time:~0,-6%
if "%ttt%"==" 5:00" (goto :time) else (goto :loop)

:time
taskkill /f /im prog.exe
goto :loop

R
rPman, 2021-09-05
@rPman

A strange requirement, the task scheduler is ideal for such tasks, it even allows you to display the window interactively (there is a checkbox in the settings).
You count how long in seconds the time you need will be (for example, after two hours - 3600 * 2 = 7200 the required time will come, then run once a day - 3600 * 24 = 86400), and write the following cmd file:

ping localhost -n 7200 > nul
:loop
taskkill /f /im myprog.exe
ping localhost -n 86400 > nul
goto :loop

Be careful, ping is not a very accurate timer, for every day the time will run away by a few seconds from the target.
Of course, you can calculate the time directly in the batch file, but this is such a hemorrhoid, a terribly inconvenient language.
ps I remind you that in all windows, starting with win7, a compiler (delivery of the .net framework) c#, .net js or .net visualbasic is included in the delivery, you can write full-fledged applications, without a development environment, in your favorite editor, compile them (including GUI and working with databases) on the command line, even with due diligence, you can build a project created in visual studio.
It lies here - C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\ (see different versions there), unfortunately Microsoft stopped supplying new versions of the compiler (5.0 and higher) with the OS, i.e. you need to install them yourself (it's free, but it negates the whole point - it's built in by default), it seems that Microsoft has relied on powershell (my opinion is inconvenient, but certainly better than cmd).
If you need something, it’s more convenient to write in these wonderful programming languages, and not on the bat / cmd hemorrhoid generator, which has been pulled for compatibility since the days of DOS

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question