Results 1 to 3 of 3

Thread: Visual Basic .NET Delete File That Is Currently 'In-Use'

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    55

    Exclamation 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!

  2. #2
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    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).
    VB 2005, Win Xp Pro sp2

  3. #3
    Addicted Member Dark Anima's Avatar
    Join Date
    Sep 2008
    Posts
    183

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width