Run Once a day ONLY Problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • morci
    Forum Member
    • Nov 2002
    • 17

    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
  • JimS
    Indigo Rose Customer
    • May 2003
    • 1057

    #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

    • Worm
      Indigo Rose Customer
      • Jul 2002
      • 3971

      #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