I'm really struggling to get a BAT script with an infinite loop to run in background on system startup.
Here's the script:
I tried:
- running from command line prompt, and it works fine
- windows task scheduler
- sc tool to add it as a service
But as a service it doesn't start.
With the scheduler it starts, writes "Script Started", enters the loop one time and writes "Check done...", but then it doesn't write anything else.
Maybe the scheduler runs it and then stops it immediately?
So, how can I make this work?
Thanks in advance!
Here's the script:
Code:
@ echo off
setlocal enabledelayedexpansion
set log=c:\testscript.log
echo %date% %time% Script started > %log%
for /l %%n in (0,0,1) do (
echo !date! !time! Check done... >> %log%
timeout 10 > nul
)
I tried:
- running from command line prompt, and it works fine
- windows task scheduler
- sc tool to add it as a service
But as a service it doesn't start.
With the scheduler it starts, writes "Script Started", enters the loop one time and writes "Check done...", but then it doesn't write anything else.
Maybe the scheduler runs it and then stops it immediately?
So, how can I make this work?
Thanks in advance!
My Computer
- Computer type
- PC/Desktop
- OS
- Windows 7 Home Premium 64bit