Solved

How to delete the current application ?

Posted on 2001-08-29
9
186 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 52

Expert Comment

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

Expert Comment

by:PaulHews
ID: 6439193
Hehe.  Cool one Ark.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

707 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