0

I have a functioning script that works as intended when ran in file explorer, but I am trying to implement a way to run the script on logon. My solution was to use task scheduler, but when I run the script the status says "running," yet, the file doesn't execute.

Here is the following code:

@echo on

if exist reboot.txt goto iterate
if not exist reboot.txt goto begin

:begin
echo HOW MANY REBOOTS DO YOU WANT?
set /p input= Enter number: 
type nul > reboot.txt
echo %input% >> reboot.txt
type nul > number.txt
echo 0 >> number.txt
goto iterate

:iterate
for /f " delims==" %%i in (number.txt) do set /A temp_counter= %%i+1 
echo %temp_counter% > number.txt 

for /f "delims=" %%i in (reboot.txt) do set Boot=%%i
echo %Boot%

if %temp_counter% GTR %Boot% (
    echo Numbers match goto end
) else (
    echo Numbers don't match
    start shutdown.exe /r /t 60
    exit
)

:end
del reboot.txt
del number.txt
exit
TylerH
  • 20,799
  • 66
  • 75
  • 101
Ant
  • 1
  • 2
    1) probably the scheduler starts the bat in the windows directory. Try to add `cd /d %~dp0` at the beginning of the file. 2) the script requires user input - how it is handled through the scheduler? – npocmaka Jul 05 '22 at 18:27
  • 1
    Yes, your first solution works! The script only requires user input once when the script is first ran and the scheduler didn't have a problem with that. It was like you said. The scheduler starts in the windows directory, and after adding that line, the bat started executing in task. Thank you very much! – Ant Jul 05 '22 at 18:57
  • Take a look at [What must be taken into account on executing a batch file as scheduled task](https://stackoverflow.com/a/41821620) – aschipfl Jul 05 '22 at 20:15

0 Answers0