Jump to content

Recommended Posts

Posted

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. 

Posted

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

Posted

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. 

Posted

Heres why you use mine :P

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 :mellow:

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

Posted (edited)

Well, that is a bug. Type selfdelete in Scite and press Ctrl+B then the function appears.

But there is a \ missing :P

$iDelay is never used either (Edit: It is :mellow: ) :party: 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 by Mat
Posted (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 by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Posted

you can also swap @AUTOITEXE with @ScriptFullPath - which handles both exe and au3

Just 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. :mellow:

Losing an executable is one thing, losing a source file is something else entirely.

wtfpl-badge-1.png

Posted

a slight curiosity as to how many people would wind up deleting thier AutoIt3.exe

Hopefully 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

Posted (edited)

Yup :mellow: 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. :P

Edited by Mobius

wtfpl-badge-1.png

Posted

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

Posted

@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. 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...