This is a bit hacky, but you could try it. It uses the AT
command to run the_programm.exe
up to a minute in the future (which it computes using the %TIME%
environment variable and SET
arithmetic).
batch.bat:
@echo off
setlocal
:: store the current time so it does not change while parsing
set t=%time%
:: parse hour, minute, second
set h=%t:~0,2%
set m=%t:~3,2%
set s=%t:~6,2%
:: reduce strings to simple integers
if "%h:~0,1%"==" " set h=%h:~1%
if "%m:~0,1%"=="0" set m=%m:~1%
if "%s:~0,1%"=="0" set s=%s:~1%
:: choose number of seconds in the future; granularity for AT is one
:: minute, plus we need a few extra seconds for this script to run
set x=70
:: calculate hour and minute to run the program
set /a x=s + x
set /a s="x %% 60"
set /a x=m + x / 60
set /a m="x %% 60"
set /a h=h + x / 60
set /a h="h %% 24"
:: schedule the program to run
at %h%:%m% c:\the_programm.exe
You can look at the AT /?
and SET /?
to see what each of these is doing. I left off the /interactive
parameter of AT
since you commented that "no user interaction is allowed".
Caveats:
- It appears that
%TIME%
is always 24-hour time, regardless of locale settings in the control panel, but I don't have any proof of this.
- If your system is loaded down and batch.bat takes more than 10 seconds to run, the
AT
command will be scheduled to run 1 day later. You can recover this manually, using AT {job} /delete
, and increase the x=70
to something more acceptable.
The START
command, unfortunately, even when given /i
to ignore the current environment, seems to pass along the open file descriptors of the parent cmd.exe
process. These file descriptors appear to be handed off to subprocesses, even if the subprocesses are redirected to NUL, and are kept open even if intermediate shell processes terminate. You can see this in Process Explorer if you have a batch file which START
s another batch file which START
s another batch file (etc.) which START
s a GUI Windows app. Once the intermediate batch files have terminated, the GUI app will own the file handles, even if it (and the intermediate batch files) were all redirected to NUL
.