Andromo - Start Making Apps - Free Signup

Announcement

Collapse

New Forum Software

If you're here, you've found the new home for our forums. There will be some bugs to iron out, so thanks for your patience...
See more
See less

Run Once a day ONLY Problem

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Run Once a day ONLY Problem

    Hi all,
    I'm trying to write a program that will always be in the windows startup group. I should run only once a day and it is executed it will check and quit if run already. Here is the logic behind it.

    Fundamentaly
    Note: AMS executable always in start up group

    Condition 1 (Run for the 1st time)
    today is Monday eg 1/3/04
    AMS runs
    executes a program
    give you 'Update complete' screen
    sleeps for 5 seconds
    then quits
    write to registry: completed date
    number of times it ran today

    [Here i dont know what else to register]

    Condition 2 (run again same day as condition 1)
    If machine is rebooted or you logon again
    AMS checks if it ran today - today is Monday eg 1/3/04
    [ I dont know how to check?]

    If it already ran today it wont run again
    and exit program
    [eg if you rebooted or you logon again 10 times
    it will only RUN ONCE today regardless on how many times the program is executed]

    How do i do this? I tried so many combinations and it either runs again and again or quits everytime

    Condition 3
    New day today - Tuesday eg 2/3/04
    Checks if it ran Today - compares today date with completed date? How to do this?
    Since it has NOT run today
    AMS will execute program
    then
    give you 'Update complete' screen
    sleeps for 5 seconds
    then quits
    also, write to registry values that it ran today,etc


    I'm SO CONFUSED with THIS
    Every time i make a way forward I get stuck or get into a BAD loop
    Does someone have an easy way to track Run Once a day only code?

    Can i email my project to someone PLEASE? To help me sort logic
    Help please
    Thanks for any help
    Morci

  • #2
    I donít have AMS5, so I canít help you directly by giving you a sample project, but here is a hint that might help you a bit. When you set the registry key to the date, use the Julian date rather than North American or European dates. The Julian date is much easier for you compare mathematically.

    So here would be the logic:
    On start up, you get todayís Julian date
    then you read the registry key for the Julian date of the last time it was updated
    If Todayís date is > date in registry key
    then you run your update
    else
    you quit

    Be sure to end your update sequence by resetting the registry to Todayís Julian date.

    I hope that helps you some.

    Comment


    • #3
      Put this in your Projects On Startup Action

      [Projects], [Actions], [On Startup] tab

      Code:
      RegValue = "";
      RegValue = Registry.GetValue(HKEY_LOCAL_MACHINE, "Software\\My App", "LastRun", false)
      if (RegValue == "") then
      	--Never Run before
      	--Run Update
      	
      	--Set Registry Value here.  You should use HKEY_LOCAL_MACHINE
      	--if you only want it to run once on a machine.
      	--Use HKEY_LOCAL_USER if you want it to run once per User that
      	--may use the machine.
      	Registry.SetValue(HKEY_LOCAL_MACHINE, "\\Software\\My App", "LastRun", System.GetDate(Date_FMT_US), REG_SZ)
      elseif RegValue < System.GetDate(DATE_FMT_US) then
      	--Run Update
      
      	--Set Registry Value here.  You should use HKEY_LOCAL_MACHINE
      	--if you only want it to run once on a machine.
      	--Use HKEY_LOCAL_USER if you want it to run once per User that
      	--may use the machine.
      	Registry.SetValue(HKEY_LOCAL_MACHINE, "\\Software\\My App", "LastRun", System.GetDate(Date_FMT_US), REG_SZ)	
      end
      --Exit app
      Application.Sleep(5000);
      Application.Exit();

      Comment

      Working...
      X