Jump to content

Compiled .exe Do Not Copy To Itself


Recommended Posts

Hi,

I'm writing a little script to do an automatic update of a client pc via a server:

my script is "au.exe" (au = auto update)

au.exe copy some files but also itself (to upgrade to a new version) here is the source:

$IniFile = "au.ini"
$IniSet  = "Settings"
$IniCpy  = "FileToCopy"

$UpdPath = IniRead($IniFile, $IniSet, "UpdPath", "error")

If $UpdPath <> "error" Then
    $FileCmp = IniRead($IniFile, $IniSet, "FileCmp", "ggw.exe")
; Lit la version du client
    $VerCli = FileGetVersion($FileCmp)
    $VerSrv = FileGetVersion($UpdPath & "\" & $FileCmp)
;   MsgBox(0, "Debug", "Update detected - Client Version: " & $VerCli & " - Server Version: " & $VerSrv)
    If Number(StringReplace($VerSrv, ".", "")) > Number(StringReplace($VerCli, ".", "")) Then
    ; Update détecté
        IniWrite("au.log", "Update Status", "Overall Update", @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & " Update detected - Client Version: " & $VerCli & " - Server Version: " & $VerSrv)
        $i = 1
        While 1
            $File = IniRead($IniFile, $IniCpy, "File" & $i, "nomorefiles")
            If $File = "nomorefiles" Then ExitLoop
        ; Copie des fichiers
            $Status = FileCopy($UpdPath & "\" & $File, "*.*", 1); Copie les fichiers en overwrite
            If $Status = 1 Then
                IniWrite("au.log", "Update Status", $File, "Successful")
            Else
                IniWrite("au.log", "Update Status", $File, "Failed")
            EndIf
            $i = $i + 1
        WEnd
    EndIf
EndIf

The FileCopy function also do a copy of au.exe from the server to au.exe on the client pc but it fails.

Is there a way to copy my au.exe overitself by itself ? :think:

Thank you

Link to comment
Share on other sites

How about a batch script?

If FileExists("updateau.bat") Then
    FileDelete("updateau.bat")
EndIf
FileWrite("updateau.bat", "ping -n 3 1.1.1.1 > NUL" & @CRLF)
FileWrite("updateau.bat", "del au.exe" & @CRLF)
FileWrite("updateau.bat", "ren aunew.exe au.exe" & @CRLF)
FileWrite("updateau.bat", "au.exe")
Run(@ComSpec & " /c updateau.bat")
Exit 0

Edit: This is the AutoIT code of course :think:

2nd edit: forgot the @CRLF

3rd edit: added ping to pause the script a bit

Edited by forger
Link to comment
Share on other sites

How about a batch script?

If FileExists("updateau.bat") Then
    FileDelete("updateau.bat")
EndIf
FileWrite("updateau.bat", "ping -n 3 1.1.1.1 > NUL" & @CRLF)
FileWrite("updateau.bat", "del au.exe" & @CRLF)
FileWrite("updateau.bat", "ren aunew.exe au.exe" & @CRLF)
FileWrite("updateau.bat", "au.exe")
Run(@ComSpec & " /c updateau.bat")
Exit 0

Edit: This is the AutoIT code of course :think:

2nd edit: forgot the @CRLF

3rd edit: added ping to pause the script a bit

Thank you i will do a test
Link to comment
Share on other sites

filemove/rename yourself to an different name (au.old or something like that) (AND YES YOU CAN RENAME A FILE IN USE !)

copy files

run the new one & have it delete the old script (commandline switch)

Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

Take a look at this thread about a self modifying exe

The top post code is modified to be working. All you have to do is to have your updateable program compiled as a a3x and lett the loader download it before it updates itself.

Link to comment
Share on other sites

Take a look at this thread about a self modifying exe

The top post code is modified to be working. All you have to do is to have your updateable program compiled as a a3x and lett the loader download it before it updates itself.

Thank you for your reply, i looked at your code Uten but i'm testing another solution because my needs are different so, once tested i will post my findings here.

Cu

Link to comment
Share on other sites

Jango,

This has been done so many times before and there are so many different ways to do it that you might get more suggestions than you want... that said, here is one more.

Have au.exe do all that you showed in your first post except the code shown below.

Have au.exe create a temporary script that contains at least this part of your original code:

While 1
    $File = IniRead($IniFile, $IniCpy, "File" & $i, "nomorefiles")
    If $File = "nomorefiles" Then ExitLoop
 ; Copie des fichiers
    $Status = FileCopy($UpdPath & "\" & $File, "*.*", 1); Copie les fichiers en overwrite
    If $Status = 1 Then
        IniWrite("au.log", "Update Status", $File, "Successful")
    Else
        IniWrite("au.log", "Update Status", $File, "Failed")
    EndIf
    $i = $i + 1
WEnd
Edit: Let au.exe exit and then the temp script runs...

See this post for help on how to create a temporary script.

http://www.autoitscript.com/forum/index.ph...showtopic=22531

hope this helps...

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...