deleteing a file (itself)

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?
wormboy__6Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

inprasCommented:
There is a API call DeleteFile("MyFile.exe") try this.
0
LeXienCommented:
You'll need to terminate the process first
0
wormboy__6Author Commented:
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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

GlenConwayCommented:
Do you need to do it immediately or can the delete happen the next time the computer reboots?
0
wormboy__6Author Commented:
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
DanielCarCommented:
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
wormboy__6Author Commented:
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
DanielCarCommented:
Did you test the example? On my machine, it doesn't leave anything...

I tested it on Windows 98 and NT4.0


Daniel      :-)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wormboy__6Author Commented:
oops sorry - i did it wrong

ok, thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.