I am working on an application in C # that does the following:
- Burn EXE to disk
- Run exe through
Process.Start()
Now I am trying to make sure that the EXE will be deleted after it is closed. The easiest way to do this is to set the option FileOptions.DeleteOnClosewhen creating the EXE using File.Create.
However, this means that EXE cannot be executed during use. When the file descriptor is closed, the EXE is immediately deleted before it can be executed.
Is there a way to keep the "weak link" to the EXE in my application, which does not block the file and allows it to execute? Alternatively, is there a way to unlock an EXE to execute with an open file descriptor? Are there any other obvious solutions that I am missing?
ACKNOWLEDGMENT A: I am aware of other methods for deleting used files that will ultimately delete the file (for example, upon reboot). However, Iām looking for a way to delete a file immediately after its launch, which is processed by the OS (for example, when you run a package that first executes the file and then deletes it, the file will remain on disk if the batch job is completed).
CLARIFICATION B: To explain the big picture: the application receives and decrypts the executable file. After decryption, the file must be executed. However, I want the decrypted version of the EXE not to remain on the disk. Ideally, I also want users to not copy the decrypted EXE. However, since the decryption application works as the same user, this will not be possible to achieve in a truly secure way, since both have the same privileges on the system.
source
share