Sign in to follow this  
Followers 0
Jango

Compiled .exe Do Not Copy To Itself

8 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

(AND YES YOU CAN RENAME A FILE IN USE !)

Yes, but try to delete it while the process is executing then you will fail. So you still need an etternal script, yes?

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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]

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