Jump to content

msgbox to popup on Monday or reminder on other days if doesn't pop up


 Share

Recommended Posts

Why create Text files?

I'd do an ini File like

[Reminder]
lastcheck=1970/01/01 00:00:00
checkedWednesday=0
lastcheckElse=1970/01/01 00:00:00

#include <date.au3>
If @WDAY = 4 and (_DateDiff("D", IniRead("config.ini", "Reminder", "lastcheck","1970/01/01 00:00:00"), _NowCalc()) > 0 and IniRead("config.ini", "Reminder", "checkedWednesday","0") = 0) _
   or _DateDiff("D", IniRead("config.ini", "Reminder", "lastcheck","1970/01/01 00:00:00"), _NowCalc()) >= 7 then
   Msgbox(0,"Reminder", "It's wednesday today! You checked the last time at " & IniRead("config.ini", "Reminder", "lastcheck","1970/01/01 00:00:00") & "!")
   IniWrite("config.ini", "Reminder", "lastcheck", _NowCalc())
   IniWrite("config.ini", "Reminder", "checkedWednesday", 1)
   IniWrite("config.ini", "Reminder", "lastcheckElse", _NowCalc())
ElseIf @wday <> 4 and _DateDiff("D", IniRead("config.ini", "Reminder", "lastcheckElse","1970/01/01 00:00:00"), _NowCalc()) >= 1 then
   Msgbox(0,"Reminder", "It's not wednesday today! You checked the last time at " & IniRead("config.ini", "Reminder", "lastcheck","1970/01/01 00:00:00") & "!")
   IniWrite("config.ini", "Reminder", "checkedWednesday", 0)
   IniWrite("config.ini", "Reminder", "lastcheckElse", _NowCalc())
EndIF

senthor

Edited by senthor
Link to comment
Share on other sites

Thanks for the code, very interesting.

How would I set it so that if it's run on Wednesday then it will not run again?.

Also if it's run on a day other than Wednesday then how would I stop it running until the next Wednesday onwards.

Thanks

Link to comment
Share on other sites

Thanks

About to try it in a minute. Only problem is that line 62 seems to have an error.

Cheers

I can't reproduce the error. It runs fine for me. What exactly is the error you are getting? :)

Why create Text files?

I'd do an ini File like

[Reminder]
lastcheck=1970/01/01 00:00:00
checkedWednesday=0
lastcheckElse=1970/01/01 00:00:00

#include <date.au3>
If @WDAY = 4 and (_DateDiff("D", IniRead("config.ini", "Reminder", "lastcheck","1970/01/01 00:00:00"), _NowCalc()) > 0 and IniRead("config.ini", "Reminder", "checkedWednesday","0") = 0) _
   or _DateDiff("D", IniRead("config.ini", "Reminder", "lastcheck","1970/01/01 00:00:00"), _NowCalc()) >= 7 then
   Msgbox(0,"Reminder", "It's wednesday today! You checked the last time at " & IniRead("config.ini", "Reminder", "lastcheck","1970/01/01 00:00:00") & "!")
   IniWrite("config.ini", "Reminder", "lastcheck", _NowCalc())
   IniWrite("config.ini", "Reminder", "checkedWednesday", 1)
   IniWrite("config.ini", "Reminder", "lastcheckElse", _NowCalc())
ElseIf @wday <> 4 and _DateDiff("D", IniRead("config.ini", "Reminder", "lastcheckElse","1970/01/01 00:00:00"), _NowCalc()) >= 1 then
   Msgbox(0,"Reminder", "It's not wednesday today! You checked the last time at " & IniRead("config.ini", "Reminder", "lastcheck","1970/01/01 00:00:00") & "!")
   IniWrite("config.ini", "Reminder", "checkedWednesday", 0)
   IniWrite("config.ini", "Reminder", "lastcheckElse", _NowCalc())
EndIF

senthor

@senthor: The code I posted doesn't use any file except the one .ini file. It could easily be modified to use registry keys in their place and have no external files at all. So what was your point? :(

Thanks for the code, very interesting.

How would I set it so that if it's run on Wednesday then it will not run again?.

Also if it's run on a day other than Wednesday then how would I stop it running until the next Wednesday onwards.

Thanks

If it is being run by a scheduled task that was configured to run once a week on Wednesdays, then that's when it will run. No logic internal to the script is required for that part.

The code I posted checks for "/backup" on the calling command line, and attempts a backup unconditionally when called that way (by the scheduled task, presumably).

At any time, manually, by a Run key, or from a shortcut in Startup, the script can be run WITHOUT the "/backup" switch, and it only check if the last backup was more than 7 days ago. If so, it prompts to run the backup. If it has been less than 7 days since the last successful backup, it just provides notification that the backups are current.

If this didn't cover all of your conditions, what is missing?

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The backup runs via the "RUN" key in the registry. This is part of the installation.

Then everytime the user logs in the code will run and make it's decision on whether it's a scheduled day or whether a reminder is required.

Just letting you know :-)

EDIT

----

At any time, manually, by a Run key, or from a shortcut in Startup, the script can be run WITHOUT the "/backup" switch, and it only check if the last backup was more than 7 days ago. If so, it prompts to run the backup. If it has been less than 7 days since the last successful backup, it just provides notification that the backups are current.

You say that it checks if the backup was more than 7 days but if it runs a reminder without the /backup then what happens if you try and run a reminder the next week?. Surely it would wait until after the last reminder day before running the backup again.

Then if I set the scheduled backup as Tuesday and don't run the schedule, then user logs in on Thursday and gets the reminder....Then the next week it wont run a reminder until Thursday?, but what about Wednesday?

Also if the schedule is Tuesday but the reminder is not run for 6 days (next monday) then I wouldn't get a reminder for another 6 days(monday), which leaves Wednesday, Thursday, Friday, Saturday, Sunday without a reminder, even though we have passed through Tuesday again?

thanks

p.s. and I got your code to work, just have a problem as stated above.

Edited by jbennett
Link to comment
Share on other sites

The backup runs via the "RUN" key in the registry. This is part of the installation.

Then everytime the user logs in the code will run and make it's decision on whether it's a scheduled day or whether a reminder is required.

Just letting you know :-)

OK, you don't want to use the Windows Task Scheduler for your backup. That requires some tweaks. We add the backup_day key to the .ini file.

EDIT

----

You say that it checks if the backup was more than 7 days but if it runs a reminder without the /backup then what happens if you try and run a reminder the next week?. Surely it would wait until after the last reminder day before running the backup again.

Then if I set the scheduled backup as Tuesday and don't run the schedule, then user logs in on Thursday and gets the reminder....Then the next week it wont run a reminder until Thursday?, but what about Wednesday?

Also if the schedule is Tuesday but the reminder is not run for 6 days (next monday) then I wouldn't get a reminder for another 6 days(monday), which leaves Wednesday, Thursday, Friday, Saturday, Sunday without a reminder, even though we have passed through Tuesday again?

thanks

p.s. and I got your code to work, just have a problem as stated above.

All of that would be covered by a true scheduled task, it would run every scheduled day regardless of when it was last run.

But you don't want to use that, so this version does it without the Task Scheduler service:

#include <Date.au3>

#cs
    INI format:
    -----------------
    [BACKUP]
    last_backup=2008/11/03 07:45:34
    last_success=2008/11/03 08:07:21
    last_outcome=success
    backup_day=4
#ce

; Check ini file
Global $sINI = @ScriptDir & "\test.ini"
If Not FileExists($sINI) Then
    MsgBox(16, "Error", "Required .ini file not found:  " & $sINI)
    Exit
EndIf
Global $sNow = _NowCalcDate()
Global $sLastBackup = IniRead($sINI, "BACKUP", "last_backup", "1970/01/01 00:00:00"); last attempt
Global $sLastOutcome = IniRead($sINI, "BACKUP", "last_outcome", ""); last outcome (success or fail)
Global $sLastSuccess = IniRead($sINI, "BACKUP", "last_success", "1970/01/01 00:00:00"); last successfull
Global $iBackupDay = Number(IniRead($sINI, "BACKUP", "backup_day", 4)); 1=Sunday, 4=Wednesday, 7=Saturday
Global $sNextBackup = IniRead($sINI, "BACKUP", "next_backup", $sNow)

If (@WDAY = $iBackupDay) And (_DateDiff("D", $sLastSuccess, $sNow) > 0) Then
; It's backup day, and it hasn't been done yet today
    
; Unconditional backup
    _RunBackup()
Else
; It's not backup day, or it has already been done today
    
; Check if backup is out of date
    If _DateDiff("D", $sLastSuccess, $sNow) < 7 Then
    ; Backups are up to date
        MsgBox(64, "Backups Current", "Backups are current." & @CRLF & _
                "Last successful backup was:  " & $sLastSuccess)
        Exit
    Else
    ; Last successful backup was more than a week ago
        If MsgBox(16 + 4, "Backup Required", "The last successful backup was more than a week ago:  " & @CRLF & _
                $sLastSuccess & @CRLF & @CRLF & _
                "Run backup now?") = 6 Then _RunBackup()
    EndIf
EndIf

Func _RunBackup()
; This is date/time of the attempt
    IniWrite($sINI, "BACKUP", "last_backup", _NowCalc())

; Backup process simulated here...
    If MsgBox(32 + 4, "Simulating backup", "Simulating backup... success?") = 6 Then
    ; simulated backup succeeded...
        IniWrite($sINI, "BACKUP", "last_outcome", "success")
        IniWrite($sINI, "BACKUP", "last_success", _NowCalc())
    Else
    ; simulated backup failed...
        IniWrite($sINI, "BACKUP", "last_outcome", "fail")
    EndIf
EndFunc  ;==>_RunBackup

The backup day is flagged by @WDAY (4=Wednesday in the example).

If it is backup day, and the last backup is more than a day old, then backup is done.

If it is not backup day, but the last backup is more than 7 days old, the user is prompted to backup.

If it is not backup day, and the last backup is less than 7 days old, the user is only informed that backups are current.

Like the last_backup key (as opposed to last_success), there is no functional need to calculate the next backup day (next_backup), but you could do it this way just for informational purposes:

; figure next backup date
$iNewBackup = 7 - (@WDAY - $iBackupDay)
If $iNewBackup > 7 Then $iBackupDay -= 7
IniWrite($sINI, "BACKUP", "next_backup", _DateAdd("D", $iNewBackup, _NowCalcDate()); Next backup date

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...