Visual Basic .NET Delete File That Is Currently 'In-Use'
Hello everyone!
I was wondering how I could delete a file that is currently in use. Well, basically the app that i'm making is an app that detects what files you download. if it detects a certain app, it trys to delete it so you can't click the 'Run' button with-in IE. But, when I try to delete it, I get the 'File is currently in-use' -exception. How could I do this? So if they download aim6.exe and my app doesn't allow it, it will delete it from the temp files so when they click run, all they get is an error like, 'Not a valid Win32 application' ...or something
Thanks!
P.S: Any code/Examples/Sources will be helpful!
Re: Visual Basic .NET Delete File That Is Currently 'In-Use'
You can use the CloseHandle api function to release an object. Unfortunately (for you) CloseHandle works only inside the process that is calling it so you have to inject the closing code into the process that is locking the file.
I usually use the CreateRemoteThread method to execute my code in other processes so may want to research that. If not, there is a .net dll that will do the work for you; here is the google translation (scroll to bottom for sample code).
Re: Visual Basic .NET Delete File That Is Currently 'In-Use'
If you have interest in manipulating other processes, this might be a really nice project for you. One way to go is finding out the function pointer of CloseHandle(), injecting a dll into your process and calling it. That's gonna take some practise though(unless you already know about this stuff), and you'll have to involve a lower level language for the dll, C is best documented for that purpose. If you don't want to go through all that, the dll Half linked you to will propably do the trick for you.