Deleting an EXE 
Author Message
 Deleting an EXE

Could anybody suggest an approach to take with the following...

I have written a simple utility using PB/DLL which is intended to shell out
to run a child program, and then, when finished,  to delete all the files
associated with the child program and itself. All the files in question
reside in the temporary directory.

Now this all works fine, except that the utility won't delete its own .EXE -
it gives an error 70 (permission denied). I can understand why this happens,
but I'm not sure how to overcome it. It seems to me that if this is the
final action of the utility then all the necessary code should be in memory
and there is no need to keep the EXE file open. But how do I close it?

Any assistance would be appreciated.



Sat, 02 Aug 2003 01:32:53 GMT  
 Deleting an EXE
You'll have to have the calling routine delete the EXE. Until the SHELLed
progam ends, Windows owns it and is VERY protective.

e.g., in your DLL:

SHELL "Child_program.exe  option1 option2"
KILL "Child_program.exe"

(Or better, CreateProcess/WaitForSingleObject)

--
Michael Mattias
Tal Systems
Racine WI USA


Quote:
> Could anybody suggest an approach to take with the following...

> I have written a simple utility using PB/DLL which is intended to shell
out
> to run a child program, and then, when finished,  to delete all the files
> associated with the child program and itself. All the files in question
> reside in the temporary directory.

> Now this all works fine, except that the utility won't delete its own
.EXE -
> it gives an error 70 (permission denied). I can understand why this
happens,
> but I'm not sure how to overcome it. It seems to me that if this is the
> final action of the utility then all the necessary code should be in
memory
> and there is no need to keep the EXE file open. But how do I close it?

> Any assistance would be appreciated.



Sat, 02 Aug 2003 05:30:18 GMT  
 Deleting an EXE
Thanks, but that isn't quite what I meant. What I want is for the calling
routine to delete itself. Deleting the child program is no problem once it
has finished running.

I have a tentative solution, but it's very kludgy. If the calling routine
shells out to a DOS utility just before it terminates, then the DOS utility
can delete the calling routine and then itself. (I *said* it was kludgy!).
But I'd still like a better solution.

Quote:

>You'll have to have the calling routine delete the EXE. Until the SHELLed
>progam ends, Windows owns it and is VERY protective.

>e.g., in your DLL:

>SHELL "Child_program.exe  option1 option2"
>KILL "Child_program.exe"

>(Or better, CreateProcess/WaitForSingleObject)

>--
>Michael Mattias
>Tal Systems
>Racine WI USA



>> Could anybody suggest an approach to take with the following...

>> I have written a simple utility using PB/DLL which is intended to shell
>out
>> to run a child program, and then, when finished,  to delete all the files
>> associated with the child program and itself. All the files in question
>> reside in the temporary directory.

>> Now this all works fine, except that the utility won't delete its own
>.EXE -
>> it gives an error 70 (permission denied). I can understand why this
>happens,
>> but I'm not sure how to overcome it. It seems to me that if this is the
>> final action of the utility then all the necessary code should be in
>memory
>> and there is no need to keep the EXE file open. But how do I close it?

>> Any assistance would be appreciated.



Sat, 02 Aug 2003 07:34:05 GMT  
 Deleting an EXE
As a PS, on re-reading your reply, I probably didn't make myself too clear
in my original message. The "calling routine" isn't a DLL - it's a
stand-alone EXE written using PB/DLL 32-bit. It has to delete its own EXE
file as a last action before termination. DOS programs can do this with no
trouble!
Quote:

>You'll have to have the calling routine delete the EXE. Until the SHELLed
>progam ends, Windows owns it and is VERY protective.

>e.g., in your DLL:

>SHELL "Child_program.exe  option1 option2"
>KILL "Child_program.exe"

>(Or better, CreateProcess/WaitForSingleObject)



Sat, 02 Aug 2003 07:38:26 GMT  
 Deleting an EXE

says...

Quote:
> Could anybody suggest an approach to take with the following...

> I have written a simple utility using PB/DLL which is intended to shell out
> to run a child program, and then, when finished,  to delete all the files
> associated with the child program and itself. All the files in question
> reside in the temporary directory.

> Now this all works fine, except that the utility won't delete its own .EXE -
> it gives an error 70 (permission denied). I can understand why this happens,
> but I'm not sure how to overcome it. It seems to me that if this is the
> final action of the utility then all the necessary code should be in memory
> and there is no need to keep the EXE file open. But how do I close it?

> Any assistance would be appreciated.

Call the Windows API MoveFileEx() to delete the file using the
MOVEFILE_DELAY_UNTIL_REBOOT option.  This deletes the file when the
system reboots.  That's how UNINSTALL programs do it.

MoveFileEx "c:\temp\myfile.exe", _
           BYVAL %NULL, _
           %MOVEFILE_DELAY_UNTIL_REBOOT

--Dave



Sun, 03 Aug 2003 10:08:18 GMT  
 Deleting an EXE

Quote:

>Call the Windows API MoveFileEx() to delete the file using the
>MOVEFILE_DELAY_UNTIL_REBOOT option.  This deletes the file when the
>system reboots.  That's how UNINSTALL programs do it.

>MoveFileEx "c:\temp\myfile.exe", _
>           BYVAL %NULL, _
>           %MOVEFILE_DELAY_UNTIL_REBOOT

Superb! Thanks very much, Dave.

John.



Sun, 03 Aug 2003 17:33:10 GMT  
 Deleting an EXE

Quote:

>>Call the Windows API MoveFileEx() to delete the file using the
>>MOVEFILE_DELAY_UNTIL_REBOOT option.  This deletes the file when the
>>system reboots.  That's how UNINSTALL programs do it.

>>MoveFileEx "c:\temp\myfile.exe", _
>>           BYVAL %NULL, _
>>           %MOVEFILE_DELAY_UNTIL_REBOOT

>Superb! Thanks very much, Dave.

>John.

PS. Er.. I hate to be a wet blanket but, having tried this out, I find that
MoveFileEx only works under Windows NT/2000
I need this to work under Windows 95/98/ME, sorry!

It seems that my kludgy DOS solution will have to do for the present.

John



Sun, 03 Aug 2003 18:16:19 GMT  
 Deleting an EXE
Even with the NT/w2k limitation, that's a pretty neat idea.

--
Michael Mattias
Tal Systems
Racine WI USA


Quote:
> Call the Windows API MoveFileEx() to delete the file using the
> MOVEFILE_DELAY_UNTIL_REBOOT option.  This deletes the file when the
> system reboots.  That's how UNINSTALL programs do it.



Sun, 03 Aug 2003 23:40:02 GMT  
 Deleting an EXE
On Wed, 14 Feb 2001 10:16:19 -0000, "John Sutcliffe"

Quote:


>>>Call the Windows API MoveFileEx() to delete the file using the
>>>MOVEFILE_DELAY_UNTIL_REBOOT option.  This deletes the file when the
>>>system reboots.  That's how UNINSTALL programs do it.
>>>MoveFileEx "c:\temp\myfile.exe", _
>>>           BYVAL %NULL, _
>>>           %MOVEFILE_DELAY_UNTIL_REBOOT
>PS. Er.. I hate to be a wet blanket but, having tried this out, I find that
>MoveFileEx only works under Windows NT/2000
>I need this to work under Windows 95/98/ME, sorry!

Investigate use of WININIT.INI under 9x to accomplish the same thing.
The MS SDK docs explain what to do.


Mon, 04 Aug 2003 16:24:50 GMT  
 Deleting an EXE
How long can the exe remain on the system without problems?

You may be able to take care of this in the registry.

-Bob


Quote:
> As a PS, on re-reading your reply, I probably didn't make myself too clear
> in my original message. The "calling routine" isn't a DLL - it's a
> stand-alone EXE written using PB/DLL 32-bit. It has to delete its own EXE
> file as a last action before termination. DOS programs can do this with no
> trouble!


> >You'll have to have the calling routine delete the EXE. Until the SHELLed
> >progam ends, Windows owns it and is VERY protective.

> >e.g., in your DLL:

> >SHELL "Child_program.exe  option1 option2"
> >KILL "Child_program.exe"

> >(Or better, CreateProcess/WaitForSingleObject)



Sat, 02 Aug 2003 10:10:20 GMT  
 Deleting an EXE


Quote:
>Could anybody suggest an approach to take with the following...

<snip>

>Now this all works fine, except that the utility won't delete its own
>.EXE <snip>
>Any assistance would be appreciated.

This sounds like you are writing some type of virus or Trojan horse.
That said, here is a possible solution.

Have your program create a .bat file and shell to that.  Your .bat file
will have to go into a loop trying to delete the .exe file.  Then it will
go into a loop deleting itself.  DEL %0 should work.

--
ATB

Charles Kincaid



Wed, 06 Aug 2003 06:51:46 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. email telling persons to delete jdbgmgr.exe (teddy bear hoax)

2. is deleting jdbgmgr.exe bad?

3. SHOULD I DELETE JDBGMGR.EXE

4. Forcing an exe to delete itself (CFW4b - Legacy)

5. Freewrap question (self deleting .exe)

6. jdbgrmgr.exe delete help??

7. jdbgmgr.exe (deleted )

8. jdbgmgr.exe virus how to get the folder back that you deleted

9. Delete key on keyboard deleting records

10. Deleted procs not deleted???

11. Delete all files in Dir or delete Dir

12. Keyboard Delete button to delete row in array

 

 
Powered by phpBB® Forum Software