AT command help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Flyingmetalyak
Posts: 5
Joined: 15 Jan 2010 20:46
Contact:

AT command help

#1 Post by Flyingmetalyak » 15 Jan 2010 20:56

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

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 18 Jan 2010 13:01

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:

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?".

adz
Posts: 4
Joined: 18 Jan 2010 17:20
Location: Hollands

#3 Post by adz » 18 Jan 2010 17:25

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.

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#4 Post by avery_larry » 19 Jan 2010 14:30

Sorry -- I just threw together something for an idea.

substring manipulation would work:

%time:~0,5% will only use the 1st 5 characters of the %time% variable. Set timetorun appropriately. Test thoroughly.

adz
Posts: 4
Joined: 18 Jan 2010 17:20
Location: Hollands

#5 Post by adz » 19 Jan 2010 15:17

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

Flyingmetalyak
Posts: 5
Joined: 15 Jan 2010 20:46
Contact:

Re: AT command help

#6 Post by Flyingmetalyak » 28 Jan 2010 16:14

Thanks, this really helps :D

Post Reply