Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hai,

i am creating one exe for opeartion ...Once the Operation done the exe want to delete automatically .

How to do that one. (Automatically want to delete that exe with out creating another exe)


Thanks.
Posted
Comments
Sergey Alexandrovich Kryukov 3-Nov-11 1:30am    
Why such a strange idea? What's the purpose?
--SA
Sergey Alexandrovich Kryukov 3-Nov-11 18:02pm    
What's your platform?
--SA

 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Nov-11 18:01pm    
It's weird that somebody voted 3 for this. A file can really be deleted using this method; my 5.
--SA
Not clear what is the scenario, what is one EXE, another EXE… You need to know one thing: it is not possible to delete any executable file loaded by a currently running process. EXE, DLL, does not matter.

—SA
 
Share this answer
 
Comments
@BangIndia 3-Nov-11 1:34am    
if i done one Operation then the exe want to delete..
Thats just a requirement ..
The exe must remove after the process over.. how to do?
Prerak Patel 3-Nov-11 1:35am    
Yes, an EXE cannot delete itself for sure, but I found some good article for self deleting EXE on CP. It's just creating a batch file at temp location and call it at the end of task.
@BangIndia 3-Nov-11 2:06am    
OK.. Good idea. but how to run that bat file..
Prerak Patel 3-Nov-11 5:16am    
Check my answer down there. I think you should have checked it by now.
Sergey Alexandrovich Kryukov 3-Nov-11 18:06pm    
Please also see my answer of how to execute a batch file.
--SA
In very simple steps, towards the end of your program you need to run a batch file (in windows) the deletes the exe.

One complexity is that the file you are deleting might still be in use. so add a suitable delay in the batch file for the exe to be deletable.
 
Share this answer
 
Comments
@BangIndia 3-Nov-11 1:35am    
How to call that one.. what patch file i want to call
[Answering a follow-up question]

It's too bad that you did not report your platform, but you did not object against the assumption it's Windows. If so, you can use ShellExecute to run the file, see http://msdn.microsoft.com/en-us/library/bb762153%28v=vs.85%29.aspx[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900