Solved

How to delete the current application ?

Posted on 2001-08-29
9
184 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
Independent Software Vendors: 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

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!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

737 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