Would it be possible to make a script expire or otherwise stop working after date?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Would it be possible to make a script expire or otherwise stop working after date?

20 Dec 2020, 11:23

hasantr wrote:
20 Dec 2020, 03:16
Do you know that if you compile the program, you won't need an autohotkey.exe?
I am currently having similar issues. I don't think I will compile my application. Because virustotal really poses a problem. I have to find a solution without compiling the application.
I wish I had a very simple exe to run my script with autohotkey exe. (virustotal positive)
I think that more AHKers have to become members of VirusTotal, and then call out various Anti-Virus companies that are blanket labeling AutoHotkey as if it was malware. By joining, people are able to vote and comment.
https://www.virustotal.com/gui/join-us
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Would it be possible to make a script expire or otherwise stop working after date?

20 Dec 2020, 11:52

SOTE wrote:
20 Dec 2020, 11:23
hasantr wrote:
20 Dec 2020, 03:16
Do you know that if you compile the program, you won't need an autohotkey.exe?
I am currently having similar issues. I don't think I will compile my application. Because virustotal really poses a problem. I have to find a solution without compiling the application.
I wish I had a very simple exe to run my script with autohotkey exe. (virustotal positive)
I think that more AHKers have to become members of VirusTotal, and then call out various Anti-Virus companies that are blanket labeling AutoHotkey as if it was malware. By joining, people are able to vote and comment.
https://www.virustotal.com/gui/join-us
No problem for autohotkey.exe. but compiled applications are thought to be viruses. I guess this will never change.
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Would it be possible to make a script expire or otherwise stop working after date?

21 Dec 2020, 04:04

hasantr wrote:
20 Dec 2020, 11:52
No problem for autohotkey.exe. but compiled applications are thought to be viruses. I guess this will never change.
This is not a valid statement, where any compiled AutoHotkey script is labeled as a virus. This is not what is happening.

Compiled AutoHotkey scripts are bound to the interpreter, so the first case, is that if the AutoHotkey.exe is identified as malware, so will the compiled script. So the primary issue of clarification is to stop auto identification of AutoHotkey.exe as malware. This should be quite easy for Anti-Virus companies, as the source code of AutoHotkey is public and to create a hash of the AutoHotkey.exe is quite easy too. In addition, AutoHotkey's situation as an interpreted scripting language is not uncommon. AutoIt, WinBatch, Lua, Python, etc... are in the same category. Most Anti-Virus companies know how to do their job properly, it's those that don't, that we have to keep vigilant about.

Other main cases, after stopping auto mislabeling of an AutoHotkey.exe as malware (false-positive) are often as follows:

1) The use of UPX, MPRESS, or any exotic packers (compression)

While their use doesn't necessarily mean anything nefarious, various Anti-Virus heuristics can get set off by them. It depends on the Anti-Virus program used, as to how it will identify the program that is using such.

2) The executable has no detail/descriptive information nor digital signature.

It doesn't mean that those executables without such will be automatically identified as malware, but it is something that can trigger Anti-Virus heuristics, especially in combination with other traits and the executable is seeing widespread use or downloading.

3) Activities of your program that are behaviorally similar to those of well known malware and are commonly considered to be dangerous.

Doing things like trying to make changes to the registry, running at startup without permission, keyloggers, storing passwords, making changes to mass numbers of files, connecting to the Internet or suspicious webservers, etc... It's not to say that any specific behavior is nefarious, but various Anti-Virus heuristics can add them up, to come to an alert.

4) The code in your executable can be identical or similar to a previously identified malware.

This is a catch-22 type of thing, where Anti-Virus companies have to be careful and professional about what they do. Because malware used code to do something nefarious, doesn't mean the use of such code is always for such a purpose. So the Anti-Virus company has to use various other indicators.

The advantage of AutoHotkey, is that the interpreter and source code can be clearly identified as separate from each other and analyzed separately. It is actually much easier to identify what is or isn't malware with a scripting language like AutoHotkey, than with various other programming languages, if the Anti-Virus company has professionals that are aware of the scripting language and know what they are doing.

In any case, companies will sometimes get this wrong or be too general, thus customers/users have to provide push-back when they get it wrong (false-positive) and let them know about it.
bobelyk
Posts: 64
Joined: 26 Jun 2021, 16:55

Re: Would it be possible to make a script expire or otherwise stop working after date?

11 Nov 2022, 20:38

mikeyww wrote:
19 Dec 2020, 18:55
Lots of options!

Below is one of the combinations.

Code: Select all

tz  = cet
url = http://worldclockapi.com/api/json/%tz%/now
WinHttp := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WinHttp.SetTimeouts(0,30000,30000,600000)
WinHttp.Open("GET", url, false), WinHttp.Send()
WinHttp.WaitForResponse(), str := StrReplace(Trim(WinHttp.ResponseText, "{}"), """"), arr := {}
Loop, Parse, str, `,
 key := StrSplit(A_LoopField,":").1, arr[key] := SubStr(A_LoopField, StrLen(key) + 2)
FormatTime, dt, % StrReplace(SubStr(arr.currentDateTime, 1, 10), "-"), MM/dd/yyyy
MsgBox, 64, The real date, %dt%
It is still working good after 2 years, Just a couple questions
1 I reduced the time values to the minimum, and the script is till alowed to be run, i guess the code just checks the time? What would need to be added for it to really make it expire?
2. What if user copies the script before running it, it will get the time the first time the script is ran, and expire after 30days, but what if the users then runs the copy of the script, does he get anohter 30days?
User avatar
mikeyww
Posts: 27370
Joined: 09 Sep 2014, 18:38

Re: Would it be possible to make a script expire or otherwise stop working after date?

12 Nov 2022, 07:30

To assess the script's validity, you would add whatever code you want. Each run of the script yields an intact process that will execute its own code. To set an expiration date, you could define a date in yyyymmdd format, and then use :arrow: EnvSub to subtract it from the current date in yyyymmdd format.

Code: Select all

expires  = 20221031
tz       = cet
url      = http://worldclockapi.com/api/json/%tz%/now
format   = MM/dd/yyyy
WinHttp := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WinHttp.SetTimeouts(0,30000,30000,600000)
WinHttp.Open("GET", url, false), WinHttp.Send()
WinHttp.WaitForResponse(), str := StrReplace(Trim(WinHttp.ResponseText, "{}"), """"), arr := {}
Loop, Parse, str, `,
 key    := StrSplit(A_LoopField,":").1, arr[key] := SubStr(A_LoopField, StrLen(key) + 2)
today   := StrReplace(SubStr(arr.currentDateTime, 1, 10), "-") ; Today
FormatTime, dt, %today%, %format%                              ; Today
days    := today
days    -= expires, D ; Subtract expiration date from today, return difference in days
FormatTime, expDt, %expires%, %format%
MsgBox, 64, Dates, Today: %dt%`n`nExpires: %expDt%`n`nDifference in days: %days%
If expired := days > 0
     MsgBox, 48, Validity, Expired!
Else MsgBox, 64, Validity, Valid!
Or possibly just (would not work for times):

Code: Select all

If (today > expires)
     MsgBox, 48, Validity, Expired!
Else MsgBox, 64, Validity, Valid!
Galakrond
Posts: 26
Joined: 18 Dec 2022, 12:23

Re: Would it be possible to make a script expire or otherwise stop working after date?

08 Apr 2023, 04:57

@mikeyww Hello there.

When i paste my code below your code, your code is working, but mine not.
Is it possible to combine these two scripts?

1-- Your code

Code: Select all

expires  = 20221031
tz       = cet
url      = http://worldclockapi.com/api/json/%tz%/now
format   = MM/dd/yyyy
WinHttp := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WinHttp.SetTimeouts(0,30000,30000,600000)
WinHttp.Open("GET", url, false), WinHttp.Send()
WinHttp.WaitForResponse(), str := StrReplace(Trim(WinHttp.ResponseText, "{}"), """"), arr := {}
Loop, Parse, str, `,
 key    := StrSplit(A_LoopField,":").1, arr[key] := SubStr(A_LoopField, StrLen(key) + 2)
today   := StrReplace(SubStr(arr.currentDateTime, 1, 10), "-") ; Today
FormatTime, dt, %today%, %format%                              ; Today
days    := today
days    -= expires, D ; Subtract expiration date from today, return difference in days
FormatTime, expDt, %expires%, %format%
MsgBox, 64, Dates, Today: %dt%`n`nExpires: %expDt%`n`nDifference in days: %days%
If expired := days > 0
     MsgBox, 48, Validity, Expired!
Else MsgBox, 64, Validity, Valid!
2-- Combine code.

Code: Select all

Loop {
IfWinActive, Raxygore
{
  PixelGetColor, color, 685, 791, RGB  
if color = 0x0C030B
   Send, 1 ; 
}
}
#IfWinActive, Raxygore
{
~f::
While GetKeyState("f") {
   PixelGetColor, color , 686 , 662
if color = 0x6C402C
   SendInput {2} ;

}
Return
}
Best regards.[/b]
ananthuthilakan
Posts: 188
Joined: 08 Jul 2019, 05:37
Contact:

Re: Would it be possible to make a script expire or otherwise stop working after date?

08 Apr 2023, 06:25

it is taking too much time to get a response from worldclockapi
it doesn't look like a reliable way to get the date
however here is one way to combine it
Also have a look at https://www.autohotkey.com/docs/v1/lib/_If.htm

Code: Select all

;~ expires  = 20221031
expires  = 20231031
tz       = cet
url      = http://worldclockapi.com/api/json/%tz%/now
format   = MM/dd/yyyy
WinHttp := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WinHttp.SetTimeouts(0,30000,30000,600000)
WinHttp.Open("GET", url, false), WinHttp.Send()
WinHttp.WaitForResponse(), str := StrReplace(Trim(WinHttp.ResponseText, "{}"), """"), arr := {}
Loop, Parse, str, `,
 key    := StrSplit(A_LoopField,":").1, arr[key] := SubStr(A_LoopField, StrLen(key) + 2)
today   := StrReplace(SubStr(arr.currentDateTime, 1, 10), "-") ; Today
FormatTime, dt, %today%, %format%                              ; Today
days    := today
days    -= expires, D ; Subtract expiration date from today, return difference in days
FormatTime, expDt, %expires%, %format%
MsgBox, 64, Dates, Today: %dt%`n`nExpires: %expDt%`n`nDifference in days: %days%
If expired := days > 0
	
MsgBox, 48, Validity, Expired!
Else 
{
MsgBox, 64, Validity, Valid!
valid_flag:=1
}



if (valid_flag!=1)
return
Loop {
ToolTip,% A_Index
IfWinActive, Raxygore
{
  PixelGetColor, color, 685, 791, RGB  
if color = 0x0C030B
   
   Send, 1 ; 

}
}
return




#IfWinActive, Raxygore
{
~f::
if (valid_flag!=1)
	return
While GetKeyState("f") {
   PixelGetColor, color , 686 , 662
if color = 0x6C402C
   SendInput {2} ;

}
Return
}


User avatar
mikeyww
Posts: 27370
Joined: 09 Sep 2014, 18:38

Re: Would it be possible to make a script expire or otherwise stop working after date?

08 Apr 2023, 06:33

You have posted two different scripts. What is your final script? What happens when you run that script? What should happen instead?

EDIT: I had not seen the post above.
Last edited by mikeyww on 08 Apr 2023, 07:15, edited 1 time in total.
ananthuthilakan
Posts: 188
Joined: 08 Jul 2019, 05:37
Contact:

Re: Would it be possible to make a script expire or otherwise stop working after date?

08 Apr 2023, 07:08

This code is made on speculation of what you might want as its not very clear from your query
timeapi.io seems to work more reliably

Code: Select all

Expire := "20231023"
try
{
url := "https://timeapi.io/api/Time/current/zone?timeZone=cet"
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", url)
whr.Send()
whr.WaitForResponse()
MsgBox, % response := whr.ResponseText
}
Catch, e
{
; cant reach the time server , so should exit the app or do something else , other wise EnvSub may subtract from current pc time which is definitely not you want 
; newDate:= (!newDate) ? 0 : newDate
msgbox, No internet
ExitApp
}
date := RegExReplace(response, ".*""date"":""([^""]*)"".*", "$1")
StringSplit, dateParts, date, /
newDate := dateParts3 . dateParts1 . dateParts2 
EnvSub, Expire, %newDate%, days
if (Expire<=0) {
msgbox, Expired
valid_flag:=0
}
Else {
MsgBox, Number of days remaining %Expire% 
valid_flag:=1  ; make use of this flag to determine wether to run or not for any parts of your script
}

if (valid_flag!=1)
return
Loop {
ToolTip,% A_Index
IfWinActive, Raxygore
{
  PixelGetColor, color, 685, 791, RGB  
if color = 0x0C030B
   
   Send, 1 ; 

}
}
return


;~ #if (valid_flag=1)

#IfWinActive, Raxygore
{
~f::
if (valid_flag!=1)
	return
While GetKeyState("f") {
   PixelGetColor, color , 686 , 662
if color = 0x6C402C
   SendInput {2} ;

}
Return
}

Thankyou mikeyww for envSub which i didnt had any idea about
If time server is not reachable i noticed that the envSub will reduce the time from system time
so it must be taken care of
Galakrond
Posts: 26
Joined: 18 Dec 2022, 12:23

Re: Would it be possible to make a script expire or otherwise stop working after date?

08 Apr 2023, 10:08

....
Last edited by Galakrond on 09 Apr 2023, 08:53, edited 1 time in total.
ananthuthilakan
Posts: 188
Joined: 08 Jul 2019, 05:37
Contact:

Re: Would it be possible to make a script expire or otherwise stop working after date?

09 Apr 2023, 01:40

It cannot delete itself !
may be you will need to make use of batch file to delete your script and delete the batch file itself .

Warning : this looks like a virus thing , and will be flagged by antiviruses
Galakrond
Posts: 26
Joined: 18 Dec 2022, 12:23

Re: Would it be possible to make a script expire or otherwise stop working after date?

09 Apr 2023, 06:39

ananthuthilakan wrote:
09 Apr 2023, 01:40
It cannot delete itself !
may be you will need to make use of batch file to delete your script and delete the batch file itself .

Warning : this looks like a virus thing , and will be flagged by antiviruses
Hello, thanks for your helps. i handled the auto deleting thing. There is last thing for me, when i opened the code script is telling the time,weekdays,days before the remaining days.

How can i hide it but not remaining days?

Image
ananthuthilakan
Posts: 188
Joined: 08 Jul 2019, 05:37
Contact:

Re: Would it be possible to make a script expire or otherwise stop working after date?

09 Apr 2023, 06:52

its the message box , remove it
it was to test you are getting a response from server

Code: Select all

Expire := "20231023"
try
{
url := "https://timeapi.io/api/Time/current/zone?timeZone=cet"
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", url)
whr.Send()
whr.WaitForResponse()
response := whr.ResponseText
}
Catch, e
{
; cant reach the time server , so should exit the app or do something else , other wise EnvSub may subtract from current pc time which is definitely not you want 
; newDate:= (!newDate) ? 0 : newDate
msgbox, No internet
ExitApp
}
date := RegExReplace(response, ".*""date"":""([^""]*)"".*", "$1")
StringSplit, dateParts, date, /
newDate := dateParts3 . dateParts1 . dateParts2 
EnvSub, Expire, %newDate%, days
if (Expire<=0) {
msgbox, Expired
valid_flag:=0
}
Else {
MsgBox, Number of days remaining %Expire% 
valid_flag:=1  ; make use of this flag to determine wether to run or not for any parts of your script
}

if (valid_flag!=1)
return
Loop {
ToolTip,% A_Index
IfWinActive, Raxygore
{
  PixelGetColor, color, 685, 791, RGB  
if color = 0x0C030B
   
   Send, 1 ; 

}
}
return


;~ #if (valid_flag=1)

#IfWinActive, Raxygore
{
~f::
if (valid_flag!=1)
	return
While GetKeyState("f") {
   PixelGetColor, color , 686 , 662
if color = 0x6C402C
   SendInput {2} ;

}
Return
}

User avatar
mikeyww
Posts: 27370
Joined: 09 Sep 2014, 18:38

Re: Would it be possible to make a script expire or otherwise stop working after date?

09 Apr 2023, 07:01

A script can delete itself.

Code: Select all

#Requires AutoHotkey v1.1.33
F3::
FileDelete % A_ScriptFullPath
MsgBox 64, Status, Done!
ExitApp
ananthuthilakan
Posts: 188
Joined: 08 Jul 2019, 05:37
Contact:

Re: Would it be possible to make a script expire or otherwise stop working after date?

09 Apr 2023, 14:09

Adding to previous reply

Edit : Compiled exe cant delete itself but script ahk can delete itself
if its exe , you may need to go down the batch file route ( users might not have ahk installed ) or create another ahk script that deletes the exe and then itself

i knew i have tried this before :!:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Galvanise, Google [Bot], Rohwedder and 170 guests