Avatar of MstrBacon
MstrBacon
 asked on

Autohotkey script doesn't work on machines that have been up for a long time.

This works great on the machine I have autohotkey installed, but not on my test machine, which doesn't. I don't think that matters, because it is compiled as an exe, right? (i know, dumb question)

My test machine has been up for 51 days. However, it only shows it have been up for one day, seven hours, 47 minutes and change.
I inserted the message box because I thought I was crazy, because when I set the max uptime to 14 days, it ran and did nothing on the machine that had been up for 51 days.

If someone (my hero Joe W.?) could please take a look at this and tell me what I am doing wrong, I would really appreciate it.

The files attached are the ahk and a screen shot showing the message box and the system uptime, so you don't think I am nuts.

Here is the code if you don't want to open the file...

#Warn,UseUnsetLocal ; warning on uninitialized variables
#NoTrayIcon ; do not show an icon in the system tray
#NoEnv ; avoid checking empty variables to see if they are environment variables
#SingleInstance ignore ; leave old instance running
SetBatchLines,-1 ; run at maximum speed

T = 20000101000000
T += A_TickCount/1000,Seconds
FormatTime FormdT, %T%, HH:mm:ss
FormatTime Days, %T%, YDay
MsgBox % Days-1 " days " FormdT

; begin params you may want to change
UptimeDaysLimit:=14
NagTimeMinutes:=15
; end params you may want to change

NagTime:=1000*60*NagTimeMinutes ; param to Sleep is in milliseconds
TryAgain:
UptimeSeconds:=A_TickCount/1000
UptimeDays:=UptimeSeconds/(60*60*24)
If (UptimeDays>UptimeDaysLimit)
{
  MsgBox,4401,This Vidant Health Computer Needs a Break!, This system has been up for %UptimeDays% days`n`nClose your open programs, then click OK to reboot`n-----or -----`nHit cancel, or Enter to be reminded again in %NagTimeMinutes% minutes.`n`n`nThanks, Vidant Health Information Services
  IfMsgBox,OK
    Shutdown,2
  Else
  {
    Sleep,%NagTime%
    Goto,TryAgain
  }
}
ExitApp
Untitled.png
RebootNag.ahk
Scripting LanguagesAutoHotkey

Avatar of undefined
Last Comment
Joe Winograd

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Joe Winograd

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Joe Winograd

The solution in post #a42093904 (and the resulting EE article) works perfectly and is exactly what the asker requested.
Your help has saved me hundreds of hours of internet surfing.
fblack61