AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

auto launch a program at a certain time

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
grbaseball



Joined: 15 Dec 2008
Posts: 2
Location: Florida

PostPosted: Mon Dec 15, 2008 4:29 am    Post subject: auto launch a program at a certain time Reply with quote

I am trying to create script to automatically launch a program at 9:00 am but only on Monday - Friday without the need of pressing any hotkeys. Basically I'd like my work pc to auto launch my main work program before I come into work so its already loaded and ready to go. I am relatively new to autohotkey but have gotten the basics down. I have looked through these forums and done searches but could really only find script that did timed actions (such as launch a process every hour) which doesn't work in my case. I would think there should be some type of command that could do something like this

#persistent
SetTimer, WorkProgram, 1000, 0

WorkProgram:
If {
system time = 09:00:00
A_day = Monday or Tuesday or Wedneday or Thursday or Friday
}
run program.exe
return

Any help or suggestions on script would be greatly appreciated as this is driving me nuts!
Back to top
View user's profile Send private message AIM Address
Slanter



Joined: 28 May 2008
Posts: 739
Location: Minnesota, USA

PostPosted: Mon Dec 15, 2008 4:47 am    Post subject: Reply with quote

This should work
Code:
#persistent
SetTimer, WorkProgram, 1000

WorkProgram:
   If (A_Hour = 9 && A_WDay > 1 && A_WDay < 7) {
      SetTimer, WorkProgram, off
      RunWait program.exe
      SetTimer, WorkProgram, 1000
   }
return

_________________
Unless otherwise stated, all code is untested

(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination.
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Mon Dec 15, 2008 6:25 am    Post subject: Reply with quote

See this post for a working example http://www.autohotkey.com/forum/post-236933.html#236933
Back to top
mikek



Joined: 21 Nov 2008
Posts: 54
Location: Monterey, California

PostPosted: Mon Dec 15, 2008 5:08 pm    Post subject: Reply with quote

Is there a benefit to using this technique over using the Scheduled Tasks control panel? I ask because I've been using the Scheduled Tasks control panel, and am wondering if the method posted has any advantages.

- Mike
Back to top
View user's profile Send private message
jaco0646



Joined: 07 Oct 2006
Posts: 3113
Location: MN, USA

PostPosted: Mon Dec 15, 2008 11:24 pm    Post subject: Reply with quote

mikek wrote:
Is there a benefit to using this technique over using the Scheduled Tasks control panel?

No. Running a script every second of every day to check the time is ridiculous. That's 604,800 iterations to launch a program 5 times. Rolling Eyes
Back to top
View user's profile Send private message Visit poster's website
evan
Guest





PostPosted: Tue Dec 16, 2008 1:39 am    Post subject: Reply with quote

method without using settimer:
Code:
hour = 09
min = 00

difhr := hour - A_hour
difmin := min - A_min

if difhr > 0
sleepH := difhr * 3600000
else
sleepH := (24 + difhr) * 3600000

if difmin > 0
sleepM := difmin * 60000
else
sleepM := (60 + difmin) * 60000

totalsleep := sleepH + sleepM

msgbox, %totalsleep%ms to %hour%:%min%

sleep %totalsleep%
Run, this program
reload

return
Back to top
grbaseball



Joined: 15 Dec 2008
Posts: 2
Location: Florida

PostPosted: Tue Dec 16, 2008 4:49 pm    Post subject: Reply with quote

I was able to use the code suggested by slanter, however I had to tweak it as it does a check every second to see if the hour is 9 which causes program.exe to get launched every second during the 9am hour. here was what i ended up with:

Code:
loop {                           
  if A_WDay between 2 and 6           
  {
    if (A_Hour = 08) and (A_Min = 55)   ; is time 8:55am?
    GoSub, AutoLogon
  }
  sleep, 1000 * 60  ; sleep for 60 seconds so only loop once per minute
}
return

AutoLogon:
Run C:\Program Files\Program.exe   ;replaced actual program name with program.exe for display purposes
return


This works assuming the pc is active and logged in. I have a separate 'stay alive' macro running to keep the PC from auto locking out at the end of the night
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group