Realm Posted June 29, 2010 Share Posted June 29, 2010 This is a 2 part question. I am creating an Installer for one of my projects that has multiple exe's. Is there a way I can script the installer to delete itself upon completion, if not, how can I detect the path where the installer is located in at time of run? To explain a bit more on the 2nd part of the question, is there a function or command I can use to call it's current path into a variable, so that I can write it to a file, so then I can call it from another script to delete the installer? I have searched the help files but to no avail. I don't think the actual code is needed, but this is what my installers basic funtions are before I add Splashscreens. ; Test Installer ;Create all the needed Directorys and Sub-Directorys DirCreate(@ProgramFilesDir & "\My Program\Extras") DirCreate(@ProgramFilesDir & "\My Program\Addons") DirCreate(@ProgramFilesDir & "\My Program\Settings") DirCreate(@ProgramFilesDir & "\My Program\Addons") DirCreate(@AppDataDir & "\VRS\My Program") ;Files to Install FileInstall("C:\My Path\Core.exe", @ProgramFilesDir & "\My Program\Core.exe") FileInstall("C:\My Path\Extra One.exe", @ProgramFilesDir & "\My Program\Extra\Extra One.exe") FileInstall("C:\My Path\Addon One.exe", @ProgramFilesDir & "\My Program\Addons\Addon One.exe") FileInstall("C:\My Path\Addon Two.exe", @ProgramFilesDir & "\My Program\Addons\Addon Two.exe") FileCreateShortcut(@ProgramFilesDir & "\My Program\Core.exe",@ProgramsDir & "\My Program\Core.exe") ;Each of these exe's are scripted to copy protect themselves upon first run. Thus the reason for the runs. RunWait(@ProgramFilesDir & "\My Program\Core.exe") RunWait(@ProgramFilesDir & "\My Program\Extra\Extra One.exe") RunWait(@ProgramFilesDir & "\My Program\Addons\Addon One.exe") RunWait(@ProgramFilesDir & "\My Program\Addons\Addon Two.exe") ;Delete Installer or pass path to txt or ini file for another script to call and delete Installer. My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. Link to comment Share on other sites More sharing options...
Xenobiologist Posted June 29, 2010 Share Posted June 29, 2010 Func _SelfDelete($iDelay = 0) Local $sCmdFile FileDelete(@TempDir & "scratch.bat") $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _ & ':loop' & @CRLF _ & 'del "' & @ScriptFullPath & '" > nul' & @CRLF _ & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _ & 'del ' & @TempDir & 'scratch.bat' FileWrite(@TempDir & "scratch.bat", $sCmdFile) Run(@TempDir & "scratch.bat", @TempDir, @SW_HIDE) EndFunc Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Mat Posted June 29, 2010 Share Posted June 29, 2010 FileWrite(@TempDir & "\TEMP_DeleteMe.bat", "DEL /Q /F """ & @ScriptFullPath & """") Run(@TempDir & "\TEMP_DeleteMe.bat") Exit AutoIt Project Listing Link to comment Share on other sites More sharing options...
Realm Posted June 29, 2010 Author Share Posted June 29, 2010 xenobiologist & Mat, Thanks for the super fast replies. I will try both versions and see what works best for my needs. Thanks Again! My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. Link to comment Share on other sites More sharing options...
Mat Posted June 29, 2010 Share Posted June 29, 2010 Heres why you use mine MsgBox(0, "Test", @TempDir & "scratch.bat") AutoIt Project Listing Link to comment Share on other sites More sharing options...
Xenobiologist Posted June 29, 2010 Share Posted June 29, 2010 Heres why you use mine MsgBox(0, "Test", @TempDir & "scratch.bat") Well, that is a bug. Type selfdelete in Scite and press Ctrl+B then the function appears. But there is a \ missing Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Mat Posted June 29, 2010 Share Posted June 29, 2010 (edited) Well, that is a bug. Type selfdelete in Scite and press Ctrl+B then the function appears.But there is a \ missing $iDelay is never used either (Edit: It is ) all in all, not the nicest bit of scripting i've ever seen.It's overkill anyway, as he wants to exit straight after, so he doesn't need the loop. Edited June 29, 2010 by Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
Mobius Posted June 29, 2010 Share Posted June 29, 2010 (edited) It's overkill anyway, as he wants to exit straight after, so he doesn't need the loop. If he is exiting on the line after the delete self code he doesn't really need to create the batch either.... ; User code Run('CMD.exe /C TYPE "'& @AUTOITEXE &'" > "'& @AUTOITEXE &'" && DEL /Q /F "'& @AUTOITEXE &'"',@SCRIPTDIR,@SW_HIDE) EXIT Edited June 29, 2010 by Mobius Link to comment Share on other sites More sharing options...
Mat Posted June 29, 2010 Share Posted June 29, 2010 Yup I didn't think of that, and that'll stop the batch file being left lying around as well. AutoIt Project Listing Link to comment Share on other sites More sharing options...
ripdad Posted June 29, 2010 Share Posted June 29, 2010 (edited) you can also swap @AUTOITEXE with @ScriptFullPath - which handles both exe and au3 - EDIT - By the way .. I tried @AUTOITEXE with au3 and it deleted my AutoIt3.exe Good thing I made a backup copy of it -> <wink> @ScriptFullPath is the way to go. Edited June 29, 2010 by ripdad "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
Mobius Posted June 29, 2010 Share Posted June 29, 2010 you can also swap @AUTOITEXE with @ScriptFullPath - which handles both exe and au3Just answering the question differently since all others had covered the Scriptfullpath macro.....oh and a slight curiosity as to how many people would wind up deleting thier AutoIt3.exe files testing that line in script form. Losing an executable is one thing, losing a source file is something else entirely. Link to comment Share on other sites More sharing options...
ripdad Posted June 29, 2010 Share Posted June 29, 2010 a slight curiosity as to how many people would wind up deleting thier AutoIt3.exeHopefully not many.Nice scriptlet .. i'm scratching the other ones i have. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
Mobius Posted June 29, 2010 Share Posted June 29, 2010 (edited) Yup I didn't think of that, and that'll stop the batch file being left lying around as well.Nothing wrong with the batch method since a batch can also self delete if a full path was used to call it by using "DEL /F %0%" as the last line in the batch. Edited June 30, 2010 by Mobius Link to comment Share on other sites More sharing options...
ripdad Posted June 29, 2010 Share Posted June 29, 2010 This should be good enough 'stalling' (about 10 seconds). If not, adjust -n 10 for higher. Run('CMD.exe /C ping -n 10 127.0.0.1 > nul && DEL /Q /F "' & @ScriptFullPath & '"', @ScriptDir, @SW_HIDE) "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
Realm Posted June 30, 2010 Author Share Posted June 30, 2010 @Mobius, Very clean and proficient step, Thanks a lot for you help! My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 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