Solved

How to delete the current application ?

Posted on 2001-08-29
9
179 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 27

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 49

Expert Comment

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

Expert Comment

by:PaulHews
ID: 6439193
Hehe.  Cool one Ark.
0
 
LVL 27

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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 27

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 27

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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 have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now