Board index » delphi » Deleting Self

Deleting Self

Is it possible to delete the exe which is running. ie I am writing an
installation program which copies some files over to the hard drive
(it is installed from CD) which are run at a later time to finalise
settings. After finalising the settings the setup program needs to
delete itself. Is this possible?

Any help would be appreciated,

Chris

 

Re:Deleting Self


I am not sure how to do it exactly, but there is a way to postpone
such actions until the next reboot - Many installers do it, and then
ask you to reboot. They use something like the AT command, scheduled
once at system boot time, to execute a script.

Hope that helps

Mike

On Wed, 18 Mar 1998 10:43:00 GMT, chris.h...@clear.net.nospam.nz

Quote
(Chris Hope) wrote:
>Is it possible to delete the exe which is running. ie I am writing an
>installation program which copies some files over to the hard drive
>(it is installed from CD) which are run at a later time to finalise
>settings. After finalising the settings the setup program needs to
>delete itself. Is this possible?

>Any help would be appreciated,

>Chris

Re:Deleting Self


Quote
Chris Hope wrote:
> Is it possible to delete the exe which is running. ie I am writing an

No, it is not possible to delete a running image. You'll have to delete
the image "post-mortem".

Quote
> settings. After finalising the settings the setup program needs to
> delete itself. Is this possible?

An obvious dirty trick is to have the program as it's last task spawn
a .bat file that first deletes the program and then itself, e.g.

:try
del %1 > nul
rem when the program terminates, you'll be able to delete it
if exist %1 goto try
del %0
--

        Roland.

---
No, I'm not a mail-chauvinist!

Re:Deleting Self


It depends on the operating system you're working under...

Windows NT allows you to use the call MoveFileEx() with a flag
MOVEFILE_DELAY_UNTIL_REBOOT

This lets you rename, copy and delete files that may be in use when
you issue the command.

Under Windows 95 it's different, as Windows 95 doesn't implement
MoveFileEx().  You can still do it though...  If Windows 95 sees a
file in the Windows directory called WININIT.INI, it executes
WININIT.EXE.  If you have entered a load of files into a [RENAME]
section of the ini file, they will be renamed.  (Rename something to
NULL to delete it).

i.e.  
[rename]
NULL=C:\DELME.EXE
C:\NEW.EXE=C:\OLD.EXE

Once WININIT.EXE has done it renames WININIT.INI as WININIT.BAK.

Hope this helps,

Cheers,

Rik
There is a file in the windows directory called WININIT.EX
On Wed, 18 Mar 1998 10:43:00 GMT, chris.h...@clear.net.nospam.nz

Quote
(Chris Hope) wrote:
>Is it possible to delete the exe which is running. ie I am writing an
>installation program which copies some files over to the hard drive
>(it is installed from CD) which are run at a later time to finalise
>settings. After finalising the settings the setup program needs to
>delete itself. Is this possible?

>Any help would be appreciated,

>Chris

--[r-bar...@visionsoft.co.uk]---------
Any views expressed are my own and may
not be those of my employer.  

Other Threads