Can an application delete itself?

  • Thread starter Thread starter Peteroid
  • Start date Start date
P

Peteroid

Can a Managed C++ application delete its own .EXE file that spawned it? Or
is it 'open?

[==Peteroid==]
 
Peteroid said:
Can a Managed C++ application delete its own .EXE file that spawned it? Or
is it 'open?

The short answer is that it can not.

There is a hack floating around the net that makes use of some undocumented
stuff and on some platforms will delete the executable when it terminates.

The supported way to do this is to call MoveFileEx() with a null target file
name and the MOVEFILE_DELAY_UNTIL_REBOOT option.

In case you don't know you can initiate a reboot with
InitiateSystemShutdown() or ExitWindowsEx().

Regards,
Will
 
Thanks! :)

William DePalo said:
The short answer is that it can not.

There is a hack floating around the net that makes use of some
undocumented stuff and on some platforms will delete the executable when
it terminates.

The supported way to do this is to call MoveFileEx() with a null target
file name and the MOVEFILE_DELAY_UNTIL_REBOOT option.

In case you don't know you can initiate a reboot with
InitiateSystemShutdown() or ExitWindowsEx().

Regards,
Will
 
Back
Top