mardi 31 mars 2015

Windows: Delete EXE after Execution

I am working on an application in C# which does the following things:



  1. Write an EXE to disk

  2. Execute the EXE through Process.Start()


I am now trying to ensure that the EXE will be deleted once it is closed. The easiest way to do so is to set the FileOptions.DeleteOnClose parameter when creating the EXE using File.Create.


However, this means that the EXE can not be executed while is in use. Once the file handle is closed, the EXE is immediately deleted before it can be executed.


Is there any way to retain a "weak reference" to the EXE in my application which does not lock the file and allows it to be executed? Alternatively, is there any way to unlock the EXE for execution with the file handle still open? Are there any other obvious solutions I am missing?


Aucun commentaire:

Enregistrer un commentaire