madasraka Posted October 21, 2010 Share Posted October 21, 2010 i have a script that downloads compressed files extracts it to temp folder and replaces files within its location using extracted files from temp folder problem is that it cant replace its self so i was thinking that maybe 1 updater can talk to main EXE and tell it to wait till UPDATER exits and then replace the updater IF UPDATER says so I have no clue exactly how i would go about even thinking of doing this but i could only come up with use of external executables such as writing another small script that would do nothing but replace the UPDATER when it updats everything else, but then who would delete this small files after it replaced UPDATED with newer version ? Maybe i could somehow send a message from one script to another saying "HEY DO THIS" hmmm maybe temporary stored blankfile as a signal to main executable to read if it exist then replace the updater ? hmmm maybe or maybe there is another way of doing it ? LOST Thanks for your ideas IF ANY Link to comment Share on other sites More sharing options...
Arion Posted October 21, 2010 Share Posted October 21, 2010 It's easier than you might think, search for 'Run' in the help file. If that doesn't help, let me know, we'll work something out. [quote]“Programming is like *ex: one mistake and you’re providing support for a lifetime.”(Michael Sinz)[/quote] [quote]“There are two ways to write error-free programs; only the third one works.”(Alan J. Perlis)[/quote] Link to comment Share on other sites More sharing options...
KaFu Posted October 21, 2010 Share Posted October 21, 2010 Take a look at seangriffins excellent ChildProc (Parallel Processing) UDF. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
eltorro Posted October 21, 2010 Share Posted October 21, 2010 If you want to replace the updater, you could add a line to the batch file in the _SelfDelete() function to copy the newer updater to the updater folder. For communicating between scripts, consider using WM_COPYDATA as suggested by KaFu. Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
madasraka Posted October 22, 2010 Author Share Posted October 22, 2010 _SelfDelete() ? thats not quiet clear Can you give me one example to use this function which does not work on its own it seems. One i could think of was FileDelete (@ScriptDir & "\1.exe") FileMove (@ScriptDir & "\1\1.exe",@ScriptDir & "\1.exe",1) where @ScriptDir & "\1\1.exe" is precompiled with msgbox only FileDelete returns 0 i would assume because its in use Thanks Link to comment Share on other sites More sharing options...
eltorro Posted October 22, 2010 Share Posted October 22, 2010 expandcollapse popupLocal $ini = @ScriptDir & "\" & StringTrimRight(@ScriptName, 3) & "ini" Local $ver = IniRead($ini, @ScriptName, "version", "12345") IniWrite($ini, @ScriptName, "version", $ver + 1) Local $newVer = IniRead($ini, @ScriptName, "version", "12345") If $newVer > $ver Then $szPath_NewUpdater = @TempDir & "\" & @ScriptName FileDelete($szPath_NewUpdater) If MsgBox(33, "SelfUpdate", "Current version is: " & $ver & @CRLF & "Newest version is: " & $newVer & @CRLF & "Click Ok to run self update.") = 1 Then ;for testing copy the current file to temp FileCopy(@ScriptFullPath, $szPath_NewUpdater, 1) If MsgBox(36, "SelfUpdate", "Do your wish to restart this program after updating?") = 6 Then _SelfUpdate($szPath_NewUpdater, 1) Else _SelfUpdate($szPath_NewUpdater) EndIf EndIf EndIf Exit Func _SelfUpdate($szPath_NewUpdater, $iRestart= 0, $iDelay = 4) Local $szCmdFile,$szRestart = "" If $iRestart Then ;restarting the updater this way allows the bat file to immediately delete itself ;whereas the bat file will hang until the updater exits. $szRestart ='rundll32 url.dll,FileProtocolHandler "'& @ScriptFullPath & '"' & @CRLF EndIf FileDelete(@TempDir & "\update.bat") $szCmdFile = 'ping -n ' & $iDelay & ' 127.0.0.1 > nul' & @CRLF _ & ':loop' & @CRLF _ & 'del "' & @ScriptFullPath & '" > nul' & @CRLF _ & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _ & 'ping -n ' & $iDelay & ' 127.0.0.1 > nul' & @CRLF _ & 'copy /y "' &$szPath_NewUpdater & '" "' & @ScriptFullPath & '" > nul' & @CRLF _ & 'ping -n ' & $iDelay & ' 127.0.0.1 > nul' & @CRLF _ & 'del "' & $szPath_NewUpdater &'" > nul' & @CRLF _ & $szRestart &'del "' & @TempDir & '\update.bat"' & @CRLF FileWrite(@TempDir & "\update.bat", $szCmdFile) Run(@TempDir & "\update.bat", @TempDir, @SW_HIDE) Exit EndFunc ;==>_SelfUpdate Pass the full path of the new updater to the self update function. Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
madasraka Posted October 23, 2010 Author Share Posted October 23, 2010 I ended up doing it this way Same script no one else involved $UpdaterFileName = "ReplaceMySlef.exe" If FileExists (@ScriptDir & "\updating.file") = 1 Then ;this code ment to run when in FireFox folder FileCopy (@ScriptFullPath, FileRead (@ScriptDir & "\updating.file"),1) ;copy its seld to previously stored path in updating.file $line = FileRead (@ScriptDir & "\updating.file") $Trim = StringTrimRight ($line,18) ;the number of characters in filename 17+1 for backslash = 18 DirRemove ($Trim & "\Source",1) ; to remove source folder FileDelete (@ScriptDir & "\updating.file") ;delet update file to prevent future exec MsgBox(64,"Update","Update Complete !") exit Else DirCreate (@TempDir & "\MyFolder") ;create temp folder FileWrite (@TempDir & "\MyFolder\updating.file",@ScriptFullPath) ;write file with fullpath to know where source is at FileCopy (@ScriptDir & "\Source\" & $UpdaterFileName, @TempDir & "\MyFolder\" & $UpdaterFileName,1) ;copy its self to @temp Run (@TempDir & "\MyFolder\" & $UpdaterFileName) ;executes copy of its self from @temp Exit Endif Simpler Smaller no need for CMD to be involved. I thought there was a better way of doing this with less then 5 lines of code maybe, but oh well. I wonder if autoit could load its self into memory and then replace its self from there ? or something similar... Good examples guys thank you very much. 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