Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

auto launch a program at a certain time


  • Please log in to reply
6 replies to this topic
grbaseball
  • Members
  • 2 posts
  • Last active: Dec 16 2008 07:41 PM
  • Joined: 15 Dec 2008
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!

Slanter
  • Members
  • 739 posts
  • Last active: Jul 08 2011 05:26 AM
  • Joined: 28 May 2008
This should work
#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.

  • Guests
  • Last active:
  • Joined: --
See this post for a working example <!-- m -->http://www.autohotke...933.html#236933<!-- m -->

mikek
  • Members
  • 161 posts
  • Last active: Nov 09 2015 05:02 PM
  • Joined: 21 Nov 2008
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

jaco0646
  • Moderators
  • 3165 posts
  • Last active: Apr 01 2014 01:46 AM
  • Joined: 07 Oct 2006

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. :roll:

evan
  • Guests
  • Last active:
  • Joined: --
method without using settimer:
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


grbaseball
  • Members
  • 2 posts
  • Last active: Dec 16 2008 07:41 PM
  • Joined: 15 Dec 2008
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:

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