AT command help
Moderator: DosItHelp
-
- Posts: 5
- Joined: 15 Jan 2010 20:46
- Contact:
AT command help
I'm trying to make a batch file that will perform a command at a specific time. I've been looking around on sites for some help with this, but I haven't been successful at getting it to work. Any help would be greatly appreciated. Also, if this would be of any help I'm trying to get it to perform the command every day. So, a way to stop that would be kinda useful. Thanks
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
Well, there's the obvious -- use the task scheduler or AT command.
But if you want to code it yourself using a script, then you'll have to use the %time% variable to compare against a set time you want something to happen:
The biggest problem with this -- is if there's some slow down or delay for whatever reason, and the if statement that compares the time does NOT happen to run at the correct time -- then the script will just wait until the next day. You can add a lot of code to run the script 1 time AFTER a given time but BEFORE another given time (so a 30 minute window where it runs 1 time) or you can add a variable like "did it run today?".
But if you want to code it yourself using a script, then you'll have to use the %time% variable to compare against a set time you want something to happen:
Code: Select all
@echo off
set timetorun=21:00
:loop
if %time%==%timetorun% goto :process
rem Delay 30 seconds
ping -n 31 -w 999 127.0.0.1
goto :loop
:process
echo Put your commands here to run at the appropriate time.
rem delay 60 seconds to make sure the current time no longer matches
rem the set timetorun
ping -n 61 -w 999 127.0.0.1
goto :loop
The biggest problem with this -- is if there's some slow down or delay for whatever reason, and the if statement that compares the time does NOT happen to run at the correct time -- then the script will just wait until the next day. You can add a lot of code to run the script 1 time AFTER a given time but BEFORE another given time (so a 30 minute window where it runs 1 time) or you can add a variable like "did it run today?".
Nice solution for this problem.
But I have some questions about it. First an addition, you need to place " before and after the variabels. ("%time%")
But the time is displayed like this: 21:00:00,00
So when the pc compares the 'timetorun' with the real time it isn't the same because the more detailed notation of the pc. How can you avoid this? I tried for example: 21:00:*,*
But i'm kind of new in this more difficult stuff.
Looking forward for your solvation.
greetings out of holland.
But I have some questions about it. First an addition, you need to place " before and after the variabels. ("%time%")
But the time is displayed like this: 21:00:00,00
So when the pc compares the 'timetorun' with the real time it isn't the same because the more detailed notation of the pc. How can you avoid this? I tried for example: 21:00:*,*
But i'm kind of new in this more difficult stuff.
Looking forward for your solvation.
greetings out of holland.
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
Yes that works!!! Great! I changed those little things in first your example and this is the result:
Code: Select all
@echo off
cls
set timetorun=21:00
:loop
if "%time:~0,5%"=="%timetorun%" goto :process
rem Delay for 30 seconds
ping localhost -n 31 >nul
goto loop
:process
start program-of-your-choice.exe
rem delay 60 seconds to make sure the current time no longer matches with the set timetorun
ping localhost -n 61 >nul
goto :loop
-
- Posts: 5
- Joined: 15 Jan 2010 20:46
- Contact:
Re: AT command help
Thanks, this really helps