P Peteroid Apr 21, 2005 #1 Can a Managed C++ application delete its own .EXE file that spawned it? Or is it 'open? [==Peteroid==]
Can a Managed C++ application delete its own .EXE file that spawned it? Or is it 'open? [==Peteroid==]
W William DePalo [MVP VC++] Apr 21, 2005 #2 Peteroid said: Can a Managed C++ application delete its own .EXE file that spawned it? Or is it 'open? Click to expand... 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
Peteroid said: Can a Managed C++ application delete its own .EXE file that spawned it? Or is it 'open? Click to expand... 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
P Peteroid Apr 22, 2005 #3 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 Click to expand...
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 Click to expand...