Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Delete .EXE on disk while executing

ltabarov
Beginner
2,449 Views
In FORTRAN, can an .EXE file delete its own image on disk at the time of execution?
0 Kudos
4 Replies
Steven_L_Intel1
Employee
2,449 Views
Fortran, the language, has no concept of file deletion nor of "EXE". What you're asking tends to be a property of the operating system, not a particular language or compiler.

I tried the experiment with CVF on Windows, and it did not work. Indeed, the documentation says that you cannot delete a file that is currently being accessed - which you can see if you try this in Windows Explorer.

Steve
0 Kudos
ltabarov
Beginner
2,449 Views
Thanks, Steve. I also tried some tricks like attempting to kill the executable on disk from a thread, etc. It didn't work. My specific problem is cleaning up after installation / uninstallation. I can do everything except deleting installer/uninstaller at the end of the respective process. How do other people solve this problem in Windows? Is there always a small leftover? After your comments, I should ask my question in a different way: Are there Windows means of erasing an executable from a hard drive while executable is still working or can executable leave a request ("will") to be deleted immediately after execution? If such means exist can they be accessed from FORTRAN?

Regards,

Lev

0 Kudos
Steven_L_Intel1
Employee
2,449 Views
Most installers use a "driver" program that unpacks files used for installation, does the install, then cleans up the unpacked files. The driver program itself (usually setup.exe) is typically not automatically deleted. If you use a standard installer creation tool, this is handled for you automatically.

I'd be annoyed if an installer deleted itself after installation.

Windows does have a mechanism for doing something close to what you want - you can specify arbitrary commands to be executed on the next reboot. You've seen this at work when you uninstall a product and it tells you a reboot is needed. See here for more information.

Steve
0 Kudos
ltabarov
Beginner
2,449 Views
I tried. It works for me. The case is closed.

Thanks a lot, Steve.


Regards,

Lev
0 Kudos
Reply