Uten Posted April 6, 2006 Posted April 6, 2006 (edited) Hi, EDIT: Modified code samples to working samples. Cudoes to @MHz for taking the time to provide _SelfeDelete() and pointing out a rather blunt error my eyes could not see. I have created a sample of a executable containing a data file which I want to be modified when the executable runs. To do this I'm wrapping up my actual application (compiled as .a3x) with a "Autoit installer" script. The installer includes aut2exe.exe, aut2exeSC.bin so I can recompile the package when my actual program terminates. The problem is that when I run the executable the it keeps a handle to itself. So I'm not able to remove or modify it. To make FileInstall happy I keep my source in the aut2exe folder (beta). expandcollapse popup; FILENAME: myapp.au3 ; PURPOSE: modify a myapp.txt file. ; Compile to a3x If FileExists("myapp.txt") Then msgbox(0,"myapp.txt Before ", FileRead("myapp.txt")) Else msgbox(0,"myapp.txt ERROR ", "Could not locate file myapp.txt in" & @CRLF & @WorkingDir) Endif FileWriteLine("myapp.txt", "Modified: " & @YEAR & "." & @MON & "." & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC) msgbox(0,"myapp.txt After", FileRead("myapp.txt")) oÝ÷ Ù«¢+Øì%195èM± ½¹Ñ¥¹¹ÔÌ(ìAUIA=Mè]ÉÁÈɽչµåÁÀ¹Í๵åÁÀ¹ÑáÐ)¥9=P ½µÁ¥±Q¡¸µÍ½à À°ÅÕ½Ðí]I9%9ÅÕ½Ðì°ÅÕ½Ðí¼½¹±äÉո̽µÁ¥±ÍÉ¥ÁÐÅÕ½Ðì¤(ÀÌØíQµÁ¥ÈôQµÁ¥ÈµÀìÅÕ½ÐìÀäÈíÔÌÀäÈìÅÕ½Ðì)}%¹¥ÑÁÁ±¥Ñ¥½¸ ÀÌØíQµÁ¥È¤(ìôôôIÕ¸ÁÁ±¥Ñ¥½¸ôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô)IÕ¹]¥Ð¡Õѽ%ÑáµÀìÅÕ½Ðì½Õѽ%ÐÍáÕÑMÉ¥ÁÐÅÕ½ÐìµÀìÀÌØíQµÁ¥ÈµÀìÅÕ½ÐíµåÁÀ¹ÍàÅÕ½Ðì°MÉ¥ÁѥȤ(ìôôô ±¸ÕÀôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô)}IÁÁÁ±¥Ñ¥½¸ ÀÌØíQµÁ¥È¤)}IÁ±M± ÅÕ½ÐíM± ½¹Ñ¥¹¹áÅÕ½Ðì°ÀÌØíQµÁ¥È°ÔÀÀ¤)á¥Ð)Õ¹}%¹¥ÑÁÁ±¥Ñ¥½¸ ÀÌØíQµÁ¥È¤(%¥É ÉÑ ÀÌØíQµÁ¥È¤(%¥±¥¹Íѱ° ÅÕ½Ðì¸ÀäÈíÕѽ%ÑM¹¥¸ÅÕ½Ðì°ÀÌØíQµÁ¥ÈµÀìÅÕ½ÐíÕѽ%ÑM¹¥¸ÅÕ½Ðì¤(%¥±¥¹Íѱ° ÅÕ½Ðì¸ÀäÈíÕÁà¹áÅÕ½Ðì°ÀÌØíQµÁ¥ÈµÀìÅÕ½ÐíÕÁà¹áÅÕ½Ðì¤(%¥±¥¹Íѱ° ÅÕ½Ðì¸ÀäÈíÕÐÉá¹áÅÕ½Ðì°ÀÌØíQµÁ¥ÈµÀìÅÕ½ÐíÕÐÉá¹áÅÕ½Ðì¤(íÕѽ%Ñ}!¥¡ ½±½È¹¥¼(%¥É ÉÑ ÀÌØíQµÁ¥ÈµÀìÅÕ½ÐìÀäÈí¥½¹ÌÅÕ½Ðì¤(%¥±¥¹Íѱ° ÅÕ½Ðì¸ÀäÈí¥½¹ÌÀäÈíÕѽ%Ñ}!¥¡ ½±½È¹¥¼ÅÕ½Ðì°|($$$$ÀÌØíQµÁ¥ÈµÀìÅÕ½ÐìÀäÈí¥½¹ÌÀäÈìÅÕ½ÐìµÀìÅÕ½ÐíÕѽ%Ñ}!¥¡ ½±½È¹¥¼ÅÕ½Ðì¤(%¥±%¹Íѱ° ÅÕ½Ðì¸ÀäÈíµåÁÀ¹ÍàÅÕ½Ðì°ÀÌØíQµÁ¥ÈµÀìÅÕ½ÐíµåÁÀ¹ÍàÅÕ½Ðì¤(%¥±%¹Íѱ° ÅÕ½Ðì¸ÀäÈíµåÁÀ¹ÑáÐÅÕ½Ðì°MÉ¥ÁѥȵÀìÅÕ½ÐìÀäÈìÅÕ½ÐìµÀìÅÕ½ÐíµåÁÀ¹ÑáÐÅÕ½Ðì°Ä¤(%¥±%¹Íѱ° ÅÕ½Ðì¸ÀäÈíM± ½¹Ñ¥¹¹ÔÌÅÕ½Ðì°ÀÌØíQµÁ¥ÈµÀìÅÕ½ÐíM± ½¹Ñ¥¹¹ÔÌÅÕ½Ðì¤$)¹Õ¹)Õ¹}IÁÁÁ±¥Ñ¥½¸ ÀÌØíQµÁ¥È¤(%¥±5½Ù¡MÉ¥ÁѥȵÀìÅÕ½ÐìÀäÈìÅÕ½ÐìµÀìÅÕ½ÐíµåÁÀ¹ÑáÐÅÕ½Ðì°ÀÌØíQµÁ¥È°Ä¤(ìÕÐÉá¹á½¥¸±Ðí¥¹¥±¹ÔÌÐìl½½ÕбÐí½ÕÑ¥±¹áÐítl½¥½¸±Ðí¥½¹¥±¹¥¼Ðítl½¹½½µÁ¥±tl½½µÀÀ´Ñtl½ÁÍ̱ÐíÁÍÍÁ¡ÉÍÐít(%IչݥРÀÌØíQµÁ¥ÈµÀìÅÕ½ÐíÕÐÉá¹áÅÕ½ÐìµÀìÅÕ½Ðì½¥¸ÅÕ½ÐìµÀìÅÕ½ÐíM± ½¹Ñ¥¹¹ÔÌÅÕ½ÐìµÀìÅÕ½Ðì½½ÕÐÅÕ½ÐìµÀìÅÕ½ÐíM± ½¹Ñ¥¹¹áÅÕ½ÐìµÀìÅÕ½Ðì½½µÀÐÅÕ½Ðì°ÀÌØíQµÁ¥È°M]}!%¤$)¹Õ¹(ìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô(ìIÁ±Ñ¡ÉÕ¹¥¹ÍÉ¥ÁÐáÕѱ¹±ÑѵÀ¥Éѽɥ̸(ìÀÌØí¥±9ÜèôQ¡¥±Ñ¼ÉÁ±MÉ¥ÁÑÕ±±AÑ (ìÀÌØíQµÁ¥Èèô¥ÉѽÉäѼ±Ñ(ìÀÌØí±äèôµÌ¡ÁÁɽáµÑ±ä¤½ÉÉÁ±¹±ÑÑ¥½¸ÑÌÁ±(ì$$Q¡±äչѥ½¸¥Ìͽ¸Á¥¹Í¼Ñ¥µ¥¹¥Ì¹½ÐÕÉѸ(ìIÑÕɸè9½Ñ¡¥¹(ìÉɽÈèôÄ° ½Õ±¹½Ð±½ÑÀÌØí¥±9Ü(ìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô)Õ¹}IÁ±M± ÀÌØí¥±9Ü°ÀÌØíQµÁ¥ÈôÅÕ½ÐìÅÕ½Ðì°ÀÌØí¥±äôÀ¤(%1½°ÀÌØíÍ µ¥±(%¥±±Ñ ÀÌØíQµÁ¥ÈµÀìÅÕ½ÐìÀäÈíÍÉÑ ¹ÐÅÕ½Ðì¤($ÀÌØíÍ µ¥±ôÌäíÁ¥¹µ¸ÄµÜÌäìµÀìÀÌØí¥±äµÀìÌäìĸĸĸÄÐì¹Õ°ÌäìµÀì I1|($$$µÀìÌäìé±½½ÀÌäìµÀì I1|($$$µÀìÌäí°ÅÕ½ÐìÌäìµÀìMÉ¥ÁÑÕ±±AÑ µÀìÌäìÅÕ½ÐìÌäìµÀì I1|($$$µÀìÌäí¥á¥ÍÐÅÕ½ÐìÌäìµÀìMÉ¥ÁÑÕ±±AÑ µÀìÌäìÅÕ½Ðì½Ñ¼±½½ÀÌäìµÀì I1(%%¥±á¥ÍÑÌ ÀÌØíQµÁ¥ÈµÀìÅÕ½ÐìÀäÈìÅÕ½ÐìµÀìÀÌØí¥±9ܤQ¡¸($$ÀÌØíÍ µ¥±ôÀÌØíÍ µ¥±µÀìÌäí½ÁäÌäìµÀìÀÌØíQµÁ¥ÈµÀìÅÕ½ÐìÀäÈìÅÕ½ÐìµÀìÀÌØí¥±9ܵÀìÌäìÅÕ½ÐìÌäìµÀìMÉ¥ÁÑÕ±±AÑ µÀìÌäìÅÕ½ÐìÌäìµÀì I1(%±Í($%5Í ½à ÄØ°ÅÕ½ÐíII=HÅÕ½Ðì°ÅÕ½Ðí ½Õ±¹½Ð±½ÑèÅÕ½ÐìµÀìÀÌØí¥±9ܤ($%MÑÉÉ½È Ä¤ìÉÉ½È ½Õ±¹½Ð±½ÑÀÌØí¥±9Ü(%¹¥($ÀÌØíÍ µ¥±ôÀÌØíÍ µ¥±µÀìÅÕ½Ðí°½½D½LÅÕ½ÐìµÀìÀÌØíQµÁ¥ÈµÀì I1($ÀÌØíÍ µ¥±ôÀÌØíÍ µ¥±µÀìÅÕ½Ðí°½½DÅÕ½ÐìµÀìÀÌØíQµÁ¥È(ì]É¥ÑÑ ¥±(%¥±]É¥Ñ ÀÌØíQµÁ¥ÈµÀìÅÕ½ÐìÀäÈíÍÉÑ ¹ÐÅÕ½Ðì°ÀÌØíÍ µ¥±¤(ìIÕ¸Ñ ¥±(%IÕ¸ ÀÌØíQµÁ¥ÈµÀìÅÕ½ÐìÀäÈíÍÉÑ ¹ÐÅÕ½Ðì°ÀÌØíQµÁ¥È°M]}!%¤)¹Õ¹ Any suggestions and/or improvements? EDIT 2: Replaced code tags with AutoIt tags. Edited September 16, 2006 by Uten 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
MHz Posted April 6, 2006 Posted April 6, 2006 FileMove(@ScriptDir, $TempDir & "myapp.txt" )That line looks like a concern. Trying to move a directory with FileMove. Call this function last before Exit. It should delete your executable and replace with your temp file. No safe guards added if the copy fails. Func _SelfDelete($iDelay = 0) Local $sCmdFile FileDelete(@TempDir & "\scratch.bat") $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _ & ':loop' & @CRLF _ & 'del "' & @ScriptFullPath & '"' & @CRLF _ & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _ & 'copy ' & @TempDir & '\SelfeContained.exe "' & @ScriptFullPath & '"' & @CRLF _ & 'del ' & @TempDir & '\scratch.bat' FileWrite(@TempDir & "\scratch.bat", $sCmdFile) Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE) EndFunc
Uten Posted April 6, 2006 Author Posted April 6, 2006 (edited) That line looks like a concern. Trying to move a directory with FileMove. :"> Erh, did not spot that one, not strange the myapp.txt did not update I figured out somthing similar to your _SelfeDelete function. Even gott the ping stuff. Since you wraped it up, a bit nicer than me, including the if exist loop I'll try it out, and modifie First Post.Thanks a lot! Edited April 6, 2006 by Uten 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
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