I would like to delete a file that is in use! Forceful deletion in other words. Thank you in advance.
Printable View
I would like to delete a file that is in use! Forceful deletion in other words. Thank you in advance.
I don't think you can.
U SURE? I've seen it before. Well, I'd like to delete my app after it's done, how would i do that?
There's been a couple of threads about this,but I forget the exact solution. I think you have to create a batch file that will delete the app and when you unload the program, shell the batch file.
batch file was going to be my suggestion, too. There's no way to kill a file while it's running. Windows simply wont allow it.
lol that's what you all think. I think I know a trick around this. You make an API timer, and execute it to run in 1 second and u shut down your APP. This timer will delete your app and then end itself!
Boy is my face red!
:rolleyes:
but won't the timer end when the app ends? and if it doesn't, then that must mean the app is still running, that means you can't delete it.
here is the batch version for self delete:
VB Code:
Private Sub Command1_Click() Open Replace(App.Path & "\Del.bat", "\\", "\") For Output As #1 Print #1, "@Echo off" Print #1, ":S" Print #1, "Del " & App.EXEName & ".exe" Print #1, "If Exist " & App.EXEName & ".exe" & " goto S" Print #1, "Del Del.bat" Close #1 Shell "Del.bat", vbHide Unload Me End Sub
use that code to unload. for example press the command button and both the app and the bat file will be deleted.
whil you cannot delete the file which is in use, you can instruct the OS to delete it upon next reboot.
In Win NT series you need to use the MoveFileEx api call, while on Win 9X series you need to create a entry into the Wininit.ini file.
Attached is a module that will delete an exe when the exe unloads.
to be honest, ur only way is to write VxDs, which VB isn't capable
of. VxD may get the opened handler, retrieve the filename,
intercept the file manipulation, then force deletion.
You must have a good knowledge in ASM and device driver
programming.
that is basically what i had up there, but longer.Quote:
Originally posted by MarkT
Attached is a module that will delete an exe when the exe unloads.