Make script expire? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
SirSocks
Posts: 360
Joined: 26 Oct 2018, 08:14

Make script expire?

26 Oct 2018, 08:18

Hello -
I would like to make my scrip expire after a specific date. I can't seem to get this working. All help is appreciated
For example.....

Code: Select all

expireDate = 20181025
if (a_now > ExpireDate)
    {
    Msgbox, Expired!
    Exitapp
    }
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Make script expire?

26 Oct 2018, 08:32

User avatar
SirSocks
Posts: 360
Joined: 26 Oct 2018, 08:14

Re: Make script expire?

26 Oct 2018, 08:48

Nextron wrote:
26 Oct 2018, 08:32
This should help: https://autohotkey.com/docs/commands/Fi ... m#YYYYMMDD
This does help for the format of the expiration date. However the entire code still isn't working :(

Code: Select all

FileSetTime, 20181025
expireDate = 20181025
if (a_now > ExpireDate)
    {
    Msgbox, Expired!
    Exitapp
    }
Do you have any other suggestions ?
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Make script expire?

26 Oct 2018, 08:56

FileSetTime isn't needed. I tried to point you to the format of A_Now which is YYYYMMDDHH24MISS and not YYYYMMDD. You can compare different date formats if you make clear it are dates. Right now you're comparing a huge number versus a much smaller number.

Code: Select all

expireDate = 20181025
EnvSub,expireDate,% A_Now,D
If (expireDate<0)
	MsgBox Expired
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Make script expire?

26 Oct 2018, 09:01

alternatively, transform ur timestamp into YYYYMMDDHHmmSS format and compare directly:

Code: Select all

expireDate = 20181025000000
if (a_now > ExpireDate)
    {
    Msgbox, Expired!
    Exitapp
    }
User avatar
SirSocks
Posts: 360
Joined: 26 Oct 2018, 08:14

Re: Make script expire?

26 Oct 2018, 09:40

Nextron wrote:
26 Oct 2018, 08:56
FileSetTime isn't needed. I tried to point you to the format of A_Now which is YYYYMMDDHH24MISS and not YYYYMMDD. You can compare different date formats if you make clear it are dates. Right now you're comparing a huge number versus a much smaller number.

Code: Select all

expireDate = 20181025
EnvSub,expireDate,% A_Now,D
If (expireDate<0)
	MsgBox Expired

Here is my entire script. The expiration date still isn't working. Notice that I set the expiration date to yesterday (October 25 2018). If the expiration script works, the function "CTRL J" should not send "test". Sadly I still get a code to disable the entire sript on a specific date. :cry:

Code: Select all

^J::
send, test
return

expireDate = 20181025
EnvSub,expireDate,% A_Now,D
If (expireDate<0)
	MsgBox Expired
If you have any other advice please let me know. Thank you!
User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Make script expire?

26 Oct 2018, 10:25

Two examples:


Expire Script:

Code: Select all

#SingleInstance, Force

ExpireDate := "20181027"
CurrentDate := SubStr(A_Now, 1, 8)

If (CurrentDate >= ExpireDate) {
	MsgBox, Expired!
	ExitApp
}

MsgBox, Not Expired!

Expire Hotkey:

Code: Select all

#SingleInstance, Force

ExpireDate := "20181027"
CurrentDate := SubStr(A_Now, 1, 8)

^J::
	If (CurrentDate >= ExpireDate) {
		MsgBox, Expired
	} Else {
		Send, Test
	}
return
User avatar
SirSocks
Posts: 360
Joined: 26 Oct 2018, 08:14

Re: Make script expire?

26 Oct 2018, 13:08

I think we're getting closer. I am now fiddling around with this script, and still have no luck. Just trying to get the .exe to exit after a specific date.

Code: Select all

#SingleInstance, Force
ExpireDate := "20181025"
CurrentDate := (A_Now)

If (CurrentDate >= ExpireDate)
	ExitApp
I am still looking for any other advice.
Thank you!
User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Make script expire?

26 Oct 2018, 13:22

SirSocks wrote:
26 Oct 2018, 13:08
I think we're getting closer. I am now fiddling around with this script, and still have no luck. Just trying to get the .exe to exit after a specific date.

Code: Select all

#SingleInstance, Force
ExpireDate := "20181025"
CurrentDate := (A_Now)

If (CurrentDate >= ExpireDate)
	ExitApp
I am still looking for any other advice.
Thank you!

I already posted a working solution based on your example. What is your complaint regarding this code?

Code: Select all

#SingleInstance, Force

ExpireDate := "20181023"
CurrentDate := SubStr(A_Now, 1, 8)

If (CurrentDate >= ExpireDate) {
	ExitApp
}

MsgBox, Not Expired!
Ruevil2
Posts: 173
Joined: 14 Jul 2014, 10:39

Re: Make script expire?

26 Oct 2018, 13:47

SirSocks wrote:
26 Oct 2018, 13:08
I think we're getting closer. I am now fiddling around with this script, and still have no luck. Just trying to get the .exe to exit after a specific date.

Code: Select all

#SingleInstance, Force
ExpireDate := "20181025"
CurrentDate := (A_Now)

If (CurrentDate >= ExpireDate)
	ExitApp
I am still looking for any other advice.
Thank you!
I think what you are after is a timer. Do you want it to regularly keep checking the date? This code will only perform one check at the start of the script and then it will never check again.

I think this is more of what you are after. Checks for expiration every 30 seconds, exits when dates match.

Code: Select all

#SingleInstance, Force
ExpireDate := "20181025"

SetTimer, CheckExpire, 30000
return

CheckExpire:
   If (A_Now >= ExpireDate)
      ExitApp
return
User avatar
SirSocks
Posts: 360
Joined: 26 Oct 2018, 08:14

Re: Make script expire?  Topic is solved

26 Oct 2018, 14:00

I already posted a working solution based on your example. What is your complaint regarding this code?

Code: Select all

#SingleInstance, Force

ExpireDate := "20181023"
CurrentDate := SubStr(A_Now, 1, 8)

If (CurrentDate >= ExpireDate) {
	ExitApp
}

MsgBox, Not Expired!

You're right! It does work :D
I had it at the very bottom of my script at first and it didn't work.
I just put it at the top of my scrip now it works amazingly!!!!!

Thank you sooooo much !!!!!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Joey5, Nerafius, Rohwedder, Tvlao and 141 guests