Jump to content
ur

How to create another exe from autoit script

Recommended Posts

I will create a form to user to enter two parameters.

The first parameter is some restricted data and the second parameter is date to expire.

When the user enters the details, the script(compiled exe) should create another exe with the first parameter hard coded and the second parameter(date) set as expiry date to exe.

So the target exe generated should not work after the expiry date.

Can anyone please suggest how to achieve this.

 

Share this post


Link to post
Share on other sites

Quite easy in fact.  Just create a file (FileOpen) and write (FileWrite) the script you want within the file using the variables as needed.  Close (FileClose) the file. Then run the au3 compiler (Aut2exe.exe) with the appropriate parameters.  Delete (FileDelete) the source script.  Run the newly generated .exe. 

Share this post


Link to post
Share on other sites

Thanks for the reply @Nine

But, we want to give direct exe (first one) to end user and he will generate the second exe whenever he want.And also want to set the expiry date also for the second exe as parameter, it should not be usable after that

 

Edited by ur

Share this post


Link to post
Share on other sites

It doesn't change what I said.  If needed just FileInstall the Aut2Exe.exe file if the user doesn't have the AutoIt on his computer.

There is multiple examples in the forum about how to manage expiry date within an autoIt script, just search for it, but the easiest way is compare dates.

Edited by Nine

Share this post


Link to post
Share on other sites

Since @Nine mentioned it, if you are comparing dates and a multi-national company (even a multi-time zone one perhaps), and if the exe will be used by others (lots of if there 😛 ), then account for time zone differences? Depends on how accurate you want to be I guess.

Share this post


Link to post
Share on other sites

Yeah, even that doubt I have.

Any suggestion on how to do that. May be by taking the timezone of the target computer where the second exe generated

Share this post


Link to post
Share on other sites

I have written an updater script to be used by Google Drive and used UTC time zones. (Could only test on "my" PC and not extensively). Haven't posted that one yet, but the idea is:

; Set Time Difference Threshold (seconds)
Local $iTimeDiffThreshold = 10

;--------------------------------------------

; UTC Time Correction
Local $tSystemUTC = _Date_Time_GetSystemTime ( )
Local $tSystem = _Date_Time_GetLocalTime ( )

Local $sSystemUTC = _Date_Time_SystemTimeToDateTimeStr($tSystemUTC, 1)
Local $sSystem = _Date_Time_SystemTimeToDateTimeStr($tSystem, 1)

Local $iUTCDiff = _DateDiff('s', $sSystemUTC, $sSystem)

;--------------------------------------------

; This part you most likely won't need. I had to do some re-arranging as the datetime formats were not similar.
; Actually scratch the above comment :) You may need to form the string like this, or maybe there is a better way of doing it? 

Local $aFileTime[6]
$aFileTime = FileGetTime($sFolderPath & "\" & $sItemPath,$FT_MODIFIED,$FT_ARRAY)

; File Exists on Client, compare Modified Time
; If Server "Newer" then Add "Updated" to Item, Add "Updated Item" to all parent folders
Local $sLocalDate = $aFileTime[0] & "/" & $aFileTime[1] & "/" & $aFileTime[2] & " " & _
                    $aFileTime[3] & ":" & $aFileTime[4] & ":" & $aFileTime[5]
Local $sServerDate = $aCompareThis[$i][17] & "/" & $aCompareThis[$i][18] & "/" & $aCompareThis[$i][19] & " " & _
                     $aCompareThis[$i][20] & ":" & $aCompareThis[$i][21] & ":" & $aCompareThis[$i][22]

;--------------------------------------------

Local $iTimeDiffSeconds = _DateDiff('s', $sLocalDate, $sServerDate) + $iUTCDiff ; Local - UTC

If $iTimeDiffSeconds >= $iTimeDiffThreshold Then ; server is newer
    ; Do stuff
EndIf

Also, this one uses modified time rather than created.

Edited by GokAy
Added "my" in bold, changed/added a comment

Share this post


Link to post
Share on other sites

Rather check the regions of the users whom you would like to use the script with.

Then create the 1st form, get inputs, create another exe

Self destruct the 1st exe/form if required, with the first parameter and the second parameter(date) set as expiry date to 2nd exe as per the region/time zones information you have gathered and set in the 2nd exe/else make it also self destruct if required if date & time found.

As @Nine said If needed just FileInstall the Aut2Exe.exe file if the user doesn't have the AutoIt on his computer. and further is trial and errors...

 

Edited by Cyborg5000

Share this post


Link to post
Share on other sites

I am not sure about this issue.  If the script is supposed to stop working (lets say) tomorrow at 10pm, why check region/time zones. Unless he wants that his script stops working all over the world at the same exact time ?  Maybe OP should give us a better explanation of what he wants to achieve.

Share this post


Link to post
Share on other sites

Will the epoch time seconds finished will fix this time zone problem?

Because we are checking only seconds here.

Like I want to check the date creation time of the exe created and it should not work if the time is more than 2 weeks.

Edited by ur

Share this post


Link to post
Share on other sites

Hey again,

I tested a few things. And here is what I noticed.

- "Created" date-time doesn't change when the updated executable name is the same. The behaviour is same even if I delete the exe manually. Maybe Windows needs time to update it, idk. Therefore, I used modified time for the sake of testing.

image.png.eeaf2f961fd57a983252dd2a149fdbc5.png

Maybe someone can enlighten us?

I am attaching the exe for you to check/test the behaviour, my time zone is UTC + 3 (10800 seconds). Validity of the exe is 2 hours (2 x 60 x 60 seconds)

test1 accounts for time zone difference, 10800 is the result of $iUTCDiff for the creator of the exe (in this case mine)

test2 just checks exe modified against current time. Same result as test1 for me of course.

 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=timecheck_test.Exe
#AutoIt3Wrapper_Compression=0
#AutoIt3Wrapper_Run_Au3Stripper=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <Date.au3>
#include <FileConstants.au3>

test1()

test2()

Func test1()

    ; UTC Time Zone of Exe Creator (seconds) + Valid seconds
    Local $iTimeDiffThreshold = 10800 + (2 * 60 * 60) ;(14 * 24 * 60 * 60)

    ;--------------------------------------------

    ; UTC Time Zone for Client
    Local $tSystemUTC = _Date_Time_GetSystemTime ( )
    Local $tSystem = _Date_Time_GetLocalTime ( )

    Local $sSystemUTC = _Date_Time_SystemTimeToDateTimeStr($tSystemUTC, 1)
    Local $sSystem = _Date_Time_SystemTimeToDateTimeStr($tSystem, 1)

    Local $iUTCDiff = _DateDiff('s', $sSystemUTC, $sSystem)

    ;--------------------------------------------

    Local $aFileTime[6]
    $aFileTime = FileGetTime(@AutoItExe, $FT_MODIFIED, $FT_ARRAY)

    Local $sLocalFileTime = $aFileTime[0] & "/" & $aFileTime[1] & "/" & $aFileTime[2] & " " & _
                            $aFileTime[3] & ":" & $aFileTime[4] & ":" & $aFileTime[5]
    Local $sLocalTime = @YEAR & "/" & @MON & "/" & @MDAY & " " & _
                         @HOUR & ":" & @MIN & ":" & @SEC

    ;--------------------------------------------

    Local $iTimeDiffSeconds = _DateDiff('s', $sLocalFileTime, $sLocalTime) + $iUTCDiff - $iTimeDiffThreshold

    If $iTimeDiffSeconds >= 0 Then
        msgbox($MB_OK,"Test1","File is not valid (since): " & abs($iTimeDiffSeconds) & " seconds")
    Else
        msgbox($MB_OK,"Test1","File is valid (for): " & abs($iTimeDiffSeconds) & " seconds")
    EndIf

EndFunc

Func test2()

    ; Valid seconds
    Local $iTimeDiffThreshold = 2 * 60 * 60

    ;--------------------------------------------

    Local $aFileTime[6]
    $aFileTime = FileGetTime(@AutoItExe, $FT_MODIFIED, $FT_ARRAY)

    Local $sLocalFileTime = $aFileTime[0] & "/" & $aFileTime[1] & "/" & $aFileTime[2] & " " & _
                            $aFileTime[3] & ":" & $aFileTime[4] & ":" & $aFileTime[5]
    Local $sLocalTime = @YEAR & "/" & @MON & "/" & @MDAY & " " & _
                         @HOUR & ":" & @MIN & ":" & @SEC

    ;--------------------------------------------

    Local $iTimeDiffSeconds = _DateDiff('s', $sLocalFileTime, $sLocalTime) - $iTimeDiffThreshold

    If $iTimeDiffSeconds >= 0 Then
        msgbox($MB_OK,"Test2","File is not valid (since): " & abs($iTimeDiffSeconds) & " seconds")
    Else
        msgbox($MB_OK,"Test2","File is valid (for): " & abs($iTimeDiffSeconds) & " seconds")
    EndIf

EndFunc

 

timecheck_test.Exe

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...