Solved

How to delete the current application ?

Posted on 2001-08-29
9
183 Views
Last Modified: 2008-02-01
How do we write code in Visual Basic that deletes the current application *.exe right after it's finished executing ?

My application is an installer that needs to clean itself right after it has done its job.
0
Comment
Question by:VBQuebec
9 Comments
 
LVL 28

Accepted Solution

by:
Ark earned 25 total points
ID: 6439092
Hi

Private Sub Kill_Me()
    '-----------make bat-File---------------
    Open App.Path + "\Delself.bat" For Append As #1
    Print #1, "@echo off"
    Print #1, ":try"
    Print #1, "del " + App.EXEName + ".exe"
    Print #1, "if exist " + App.EXEName + ".exe goto try"
    Print #1, "del " + App.Path + "\Delself.bat"
    Close #1
    '--------------------------------
    Shell App.Path + "\Delself.bat", vbHide
End Sub

'Add call to above function at form_unload event or from Sub Main if you don't have form:


Private Sub Form_Unload(Cancel As Integer)
   Kill_Me
End Sub

Cheers


0
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 6439100
<listening..>
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6439193
Hehe.  Cool one Ark.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 28

Expert Comment

by:Ark
ID: 6439224
Back to old DOS times :)
Just to explain:
The trick is that VB Shell and DOS bat executes asynchroneously. Basically, you can call Kill_Me even at Form_Load event and while your code will execute bat file will continue loop <<try: - goto try>> generating error "access denied" and only after your app finished it delete your app and itself.

Cheers
0
 

Expert Comment

by:DrVannacult
ID: 6439442
brain's power!
0
 
LVL 11

Expert Comment

by:Otana
ID: 6439504
cool one. is there a limit to the number of loops the .bat can go through?
0
 
LVL 28

Expert Comment

by:Ark
ID: 6440032
Forever :)
0
 

Author Comment

by:VBQuebec
ID: 6445664
I only had to modify the line
Print #1, "del " + App.Path + "\Delself.bat"
for this line
Print #1, "del Delself.bat"

But actually, your code is Excellent :o)
It surely helps to have that DOS days background for those silly but helpful batch files.
0
 
LVL 28

Expert Comment

by:Ark
ID: 6446917
>>your code is Excellent<< = "B"???
What is "A" in this case???
Anyway, thanks for points, glad I could help you
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question