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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top