LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way for a VI to delete itself?

Solved!
Go to solution

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?

0 Kudos
Message 1 of 4
(1,099 Views)
Solution
Accepted by topic author AeroSoul

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…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 4
(1,091 Views)

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 🙂

0 Kudos
Message 3 of 4
(1,062 Views)

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

Message 4 of 4
(1,015 Views)