Jango Posted April 7, 2006 Share Posted April 7, 2006 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 ? Thank you Link to comment Share on other sites More sharing options...
forger Posted April 7, 2006 Share Posted April 7, 2006 (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 2nd edit: forgot the @CRLF 3rd edit: added ping to pause the script a bit Edited April 7, 2006 by forger Link to comment Share on other sites More sharing options...
Jango Posted April 7, 2006 Author Share Posted April 7, 2006 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 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 More sharing options...
w0uter Posted April 7, 2006 Share Posted April 7, 2006 (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 April 7, 2006 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 More sharing options...
MHz Posted April 7, 2006 Share Posted April 7, 2006 (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? Link to comment Share on other sites More sharing options...
Uten Posted April 7, 2006 Share Posted April 7, 2006 Take a look at this thread about a self modifying exeThe 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. Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
Jango Posted April 12, 2006 Author Share Posted April 12, 2006 Take a look at this thread about a self modifying exeThe 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 More sharing options...
herewasplato Posted April 12, 2006 Share Posted April 12, 2006 (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 WEndEdit: 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=22531hope this helps... Edited April 12, 2006 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now