[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

deleteing a file (itself)

Posted on 1999-12-17
9
Medium Priority
?
144 Views
Last Modified: 2010-05-02
Is it possible to delete a file that is running - ie stop it running and delete it - without using an external program?

Is there an api call or something that can be called to do this?
0
Comment
Question by:wormboy__6
9 Comments
 
LVL 4

Expert Comment

by:inpras
ID: 2291891
There is a API call DeleteFile("MyFile.exe") try this.
0
 

Expert Comment

by:LeXien
ID: 2291944
You'll need to terminate the process first
0
 

Author Comment

by:wormboy__6
ID: 2292445
But if i terminate the process then i cannot call the delete api....as my application is no longer running.

So basically is it possible?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Expert Comment

by:GlenConway
ID: 2292553
Do you need to do it immediately or can the delete happen the next time the computer reboots?
0
 

Author Comment

by:wormboy__6
ID: 2292794
Immediatly...or a few seconds later.

Itd be easy to do it when the computer rebooted. But what i want is deletion basically straight away.
0
 

Expert Comment

by:DanielCar
ID: 2293048
Good Morning Wormboy!

Try something like this:

Private Sub cmdKill_Click()
    Dim RetVal
   
    Open "Test.bat" For Output As #1
    Print #1, ":start"
    Print #1, "@del Test.exe"
    Print #1, "@dir"
    Print #1, "@if exist Test.EXE goto :start"
    Print #1, "@del test.bat"
    Close #1

    RetVal = Shell("test.bat", 6)
    End
   
End Sub

Basically, a batch file gets created that tries to delete the program, and it loops until the program terminates. When the program does terminate, the batch file erases itself.

Obviously, the program is called test.exe.

Regards.


Daniel       :-)
0
 

Author Comment

by:wormboy__6
ID: 2318458
sorry but then it leaves that file there and i would like a way to remove a file without leaving any other files behind.
0
 

Accepted Solution

by:
DanielCar earned 80 total points
ID: 2318968
Did you test the example? On my machine, it doesn't leave anything...

I tested it on Windows 98 and NT4.0


Daniel      :-)
0
 

Author Comment

by:wormboy__6
ID: 2319164
oops sorry - i did it wrong

ok, thanks
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

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…
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…
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…
Suggested Courses

590 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