0

I want to create self deleting dart executable compiled with dart2native. I was able to do it in java but when trying to do it in dart compiled to native binary, the following error appears:

FileSystemException: Cannot delete file, path = 'C:\Users\user\Desktop\Dart\self_relocation\test.exe' (OS Error: The process cannot access the file because it is being used by another process.

I understand why it doesn't work but I know that it's possible to do it in java, c++, c or even c#. Is there any way to do it only in dart ? I want to avoid making external scripts.

jamesdlin
  • 65,531
  • 13
  • 129
  • 158
  • See [How can a program delete its own executable](https://stackoverflow.com/q/1606140/179715). Windows will open a file handle to the running executable, and that will prevent it from being deleted. An executable on Windows generally cannot delete itself without some trickery (e.g. spawning a `cmd` process to run a script to delete the file). – jamesdlin Jun 01 '22 at 16:38

0 Answers0