Sign in to follow this  
Followers 0
Innovative

Update Idea

7 posts in this topic

Hello ,

I have a idea on how to update a program

We can programmed it to write a regkey to detect when its X days then it will prompt the user if they want to update

If the user wanted to update, the program will automatically install the updated version from the link we've given to upload the updated version and automatically DELETES the old version

You guys should understand me.

Can someone please design this script for me? Urgent.

Sincerely thanks in advance =\ really hopes someone will make 1 for me.

Thank you,

CrazeStar1074

Share this post


Link to post
Share on other sites



Just store the beginning date in this format:

YYYY/MM/DD HH:MM:SS

1970/01/01 00:00:00

Then when you are ready to check if its outdated:

$X = 10

If _DateDiff("D", $DateStoredInRegistry, _NowCalc()) > $X

Share this post


Link to post
Share on other sites

Works for me over a LAN, could be adapted easily for updating across the WAN.

; <top of script>
If @Compiled Then _AutoUpdate($CmdLine, $fileLocal, $fileRemote)

; <rest of script>

#region Function: _AutoUpdate()
Func _AutoUpdate($sz_CommandParam, $sz_fileSelf, $sz_fileRemote)
;~ If @Compiled Then _AutoUpdate($CmdLine, "local", "remote")
    If WinExists("AutoUpdate") Then
        If Not WinWaitClose("AutoUpdate", "", 30) Then
            MsgBox(0, "AutoUpdate", "Error#:311" & @LF & "Error updating.  Contact developer.")
            SetError(4)
            Return -1
        EndIf
    EndIf
    Local $sz_dateSelf = "", $sz_dateRemote = ""
    Local $funcTemp = "", $t = "", $sz_WinTitleOld = AutoItWinGetTitle()
    Local $i_min = -3600, $i_max = 3600
    AutoItWinSetTitle("AutoUpdate")
    If Not FileExists($sz_fileRemote) Then
        MsgBox(0, "AutoUpdate", "Error#:187" & @LF & "Update file not found.  Program will continue normally")
        SetError(0)
        SetExtended(1)
        AutoItWinSetTitle($sz_WinTitleOld)
        Return 0
    EndIf
    ; check here for command line parameters
    If $sz_CommandParam[0] > 0 Then ; commandline passed!
        If $sz_CommandParam[1] = "-update"  Then
            ; 5a) If -update has been called, this is the temp file running.
            ;    Copy the remote to the user's normal local folder, run the updated local, self-delete and exit.
            FileCopy($sz_fileRemote, $sz_fileSelf, 1)
            For $funcTemp = 0 To 2
                FileSetTime($sz_fileSelf, FileGetTime($sz_fileRemote, $funcTemp, 1), $funcTemp)
                Sleep(10)
            Next
            MsgBox(0, $version, "Update to version " & FileGetVersion($sz_fileRemote) & " complete.")
            Run($sz_fileSelf)
            _SelfDelete()
            Exit
        Else
            ; 5b) If any other command line parameter has been called.   Die.  Horribly. [optional]
            ; MsgBox(0, "AutoUpdate", "Error#: 911" & @LF & "Bad Command Line Parameter(s)" & @LF & "I only accept -update at this time.")
            ; Exit
        EndIf
    Else ; no command line passed
        ; 1) Get file date on self.
        $t = FileGetTime($sz_fileSelf, 1)
        If Not @error Then
            $sz_dateSelf = $t[0] & "/" & $t[1] & "/" & $t[2] & " " & $t[3] & ":" & $t[4] & ":" & $t[5]
        Else
            AutoItWinSetTitle($sz_WinTitleOld)
            SetError(1)
            Return -1
        EndIf
        ; 2) Get file date on file in remote location
        $t = FileGetTime($sz_fileRemote, 1)
        If Not @error Then
            $sz_dateRemote = $t[0] & "/" & $t[1] & "/" & $t[2] & " " & $t[3] & ":" & $t[4] & ":" & $t[5]
        Else
            AutoItWinSetTitle($sz_WinTitleOld)
            SetError(2)
            Return -1
        EndIf
        ; 3) Determine if remote is newer
        $t = _DateDiff('s', $sz_dateSelf, $sz_dateRemote)
        If @error Then
            AutoItWinSetTitle($sz_WinTitleOld)
            SetError(3)
            Return -1
        EndIf
        Switch $t
            Case $i_min To $i_max
                ; 4a) If the remote is an hour or less different, don't bother.
                AutoItWinSetTitle($sz_WinTitleOld)
                Return $t
            Case Else
                ; 4b) Otherwise, copy remote into temp folder with random name.
                ;     Execute the temp with command line parameter and terminate.
                MsgBox(0, "AutoUpdate", "Starting Update Procedure", 10)
                $funcTemp = Random(1001, 9999, 1)
                FileCopy($sz_fileRemote, @TempDir & "\AUD-" & $funcTemp & ".exe")
                Run(@ComSpec & " /c " & @TempDir & '"\AUD-' & $funcTemp & '.exe" -update', "", @SW_HIDE)
                Exit
        EndSwitch
    EndIf
EndFunc   ;==>_AutoUpdate
#endregion
#region Function: _SelfDelete()
Func _SelfDelete($iDelay = 3)
    Local $sCmdFile
    FileDelete(@TempDir & "\scratch.bat")
    $sCmdFile = 'ping -n ' & $iDelay & ' 127.0.0.1 > nul' & @CRLF _
             & ':loop' & @CRLF _
             & 'del "' & @ScriptFullPath & '" > nul' & @CRLF _
             & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
             & 'del ' & @TempDir & '\scratch.bat' 
    FileWrite(@TempDir & "\scratch.bat", $sCmdFile)
    Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE)
EndFunc   ;==>_SelfDelete
#endregion

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

Works for me over a LAN, could be adapted easily for updating across the WAN.

; <top of script>
If @Compiled Then _AutoUpdate($CmdLine, $fileLocal, $fileRemote)

; <rest of script>

#region Function: _AutoUpdate()
Func _AutoUpdate($sz_CommandParam, $sz_fileSelf, $sz_fileRemote)
;~ If @Compiled Then _AutoUpdate($CmdLine, "local", "remote")
    If WinExists("AutoUpdate") Then
        If Not WinWaitClose("AutoUpdate", "", 30) Then
            MsgBox(0, "AutoUpdate", "Error#:311" & @LF & "Error updating.  Contact developer.")
            SetError(4)
            Return -1
        EndIf
    EndIf
    Local $sz_dateSelf = "", $sz_dateRemote = ""
    Local $funcTemp = "", $t = "", $sz_WinTitleOld = AutoItWinGetTitle()
    Local $i_min = -3600, $i_max = 3600
    AutoItWinSetTitle("AutoUpdate")
    If Not FileExists($sz_fileRemote) Then
        MsgBox(0, "AutoUpdate", "Error#:187" & @LF & "Update file not found.  Program will continue normally")
        SetError(0)
        SetExtended(1)
        AutoItWinSetTitle($sz_WinTitleOld)
        Return 0
    EndIf
    ; check here for command line parameters
    If $sz_CommandParam[0] > 0 Then ; commandline passed!
        If $sz_CommandParam[1] = "-update"  Then
            ; 5a) If -update has been called, this is the temp file running.
            ;    Copy the remote to the user's normal local folder, run the updated local, self-delete and exit.
            FileCopy($sz_fileRemote, $sz_fileSelf, 1)
            For $funcTemp = 0 To 2
                FileSetTime($sz_fileSelf, FileGetTime($sz_fileRemote, $funcTemp, 1), $funcTemp)
                Sleep(10)
            Next
            MsgBox(0, $version, "Update to version " & FileGetVersion($sz_fileRemote) & " complete.")
            Run($sz_fileSelf)
            _SelfDelete()
            Exit
        Else
            ; 5b) If any other command line parameter has been called.   Die.  Horribly. [optional]
            ; MsgBox(0, "AutoUpdate", "Error#: 911" & @LF & "Bad Command Line Parameter(s)" & @LF & "I only accept -update at this time.")
            ; Exit
        EndIf
    Else ; no command line passed
        ; 1) Get file date on self.
        $t = FileGetTime($sz_fileSelf, 1)
        If Not @error Then
            $sz_dateSelf = $t[0] & "/" & $t[1] & "/" & $t[2] & " " & $t[3] & ":" & $t[4] & ":" & $t[5]
        Else
            AutoItWinSetTitle($sz_WinTitleOld)
            SetError(1)
            Return -1
        EndIf
        ; 2) Get file date on file in remote location
        $t = FileGetTime($sz_fileRemote, 1)
        If Not @error Then
            $sz_dateRemote = $t[0] & "/" & $t[1] & "/" & $t[2] & " " & $t[3] & ":" & $t[4] & ":" & $t[5]
        Else
            AutoItWinSetTitle($sz_WinTitleOld)
            SetError(2)
            Return -1
        EndIf
        ; 3) Determine if remote is newer
        $t = _DateDiff('s', $sz_dateSelf, $sz_dateRemote)
        If @error Then
            AutoItWinSetTitle($sz_WinTitleOld)
            SetError(3)
            Return -1
        EndIf
        Switch $t
            Case $i_min To $i_max
                ; 4a) If the remote is an hour or less different, don't bother.
                AutoItWinSetTitle($sz_WinTitleOld)
                Return $t
            Case Else
                ; 4b) Otherwise, copy remote into temp folder with random name.
                ;     Execute the temp with command line parameter and terminate.
                MsgBox(0, "AutoUpdate", "Starting Update Procedure", 10)
                $funcTemp = Random(1001, 9999, 1)
                FileCopy($sz_fileRemote, @TempDir & "\AUD-" & $funcTemp & ".exe")
                Run(@ComSpec & " /c " & @TempDir & '"\AUD-' & $funcTemp & '.exe" -update', "", @SW_HIDE)
                Exit
        EndSwitch
    EndIf
EndFunc   ;==>_AutoUpdate
#endregion
#region Function: _SelfDelete()
Func _SelfDelete($iDelay = 3)
    Local $sCmdFile
    FileDelete(@TempDir & "\scratch.bat")
    $sCmdFile = 'ping -n ' & $iDelay & ' 127.0.0.1 > nul' & @CRLF _
             & ':loop' & @CRLF _
             & 'del "' & @ScriptFullPath & '" > nul' & @CRLF _
             & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
             & 'del ' & @TempDir & '\scratch.bat' 
    FileWrite(@TempDir & "\scratch.bat", $sCmdFile)
    Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE)
EndFunc   ;==>_SelfDelete
#endregion
I wanted it to download from a hosted site like www.ripway.com

Share this post


Link to post
Share on other sites

Do it yourself. Like I said, it could be adapted for a WAN. I'm not going to spoon feed you.


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

Im quite new to Autoit and whats WAN ? How do i DIY -__- ? SOrry for the troubles.

Share this post


Link to post
Share on other sites

WAN = Wide Area Network = Internet.

Instead of having the program copy from a folder, have it use INetGet and download a flag file to a temp folder and check for updates that way.

Use of a flag file is recommended since those can be flat text on the order of less than a kbyte and saves a ton of bandwidth.


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

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
Sign in to follow this  
Followers 0