07-06-2021 03:50 AM
Hello
I'm making an installer, that creates a folder structure and populates it with certain files. One of the files is zipped (database from one of my previous posts) and i created an executable to unzip it, which is ran at the end of the installation. Now i'd like for that executable to delete itself, so it wouldn't be present in the system.
Is there any way to do that or would i need yet another vi to do it?
Solved! Go to Solution.
07-06-2021 04:03 AM
Hi AeroSoul,
@AeroSoul wrote:
One of the files is zipped (database from one of my previous posts) and i created an executable to unzip it, which is ran at the end of the installation. Now i'd like for that executable to delete itself, so it wouldn't be present in the system.
Is there any way to do that or would i need yet another vi to do it?
You are mixing "VI" and "executable": these are two very different things!
A running executable cannot delete its own file on harddrive because Windows will prevent that: you need another tool to delete the executable file.
What about using a script/batchfile to run that executable and delete it afterwards? That script first calls your executable, then waits for some seconds (to give some time for Windows to cleanup the executable and release the file), then delete the executable…
07-06-2021 05:05 AM
This batch trick might just work, according to this thread it can delete itself.
Will have to fiddle around a bit as i've never actually written a meaningful batch script tho...
Thanks 🙂
07-06-2021 08:02 AM
For anyone looking at how to do this in the future, the content of the entire batch file is basically this:
--------------
START /W path\app.exe* (/w waits for app to stop executing before proceeding)
DEL path\app.exe* /f /q (/f force deletes read-only files, /q does not ask for prompt when deleting)
call :end&exit /b
:end
start /b "" cmd /c del "%~f0"&exit /b (this whole shebang deletes the batch file itself)
---------------
This batch file can run by itself only on files without admin privileges, if you need admin privileges, you'll need another line at the start of the file, but that makes it execute twice and isn't as pretty.
* is example path