Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to delete the current application ?

Posted on 2001-08-29
9
Medium Priority
?
191 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 75 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 53

Expert Comment

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

Expert Comment

by:PaulHews
ID: 6439193
Hehe.  Cool one Ark.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 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…
Suggested Courses

636 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