Deleting an exe in code gives "Access To Path c:\'Myfolder\myfile.exe" is denied

Posted on 2006-05-23
Last Modified: 2010-04-23
I have an application that is supposed to autoupdated itself when it sees a file in a certain directory at the start of running the application.

The application, in order to update itself, runs a very small utility application that simply closes the original application, waits 10 seconds to ensure it is properly closed, deletes the original application exe file and then moves the replacement into place from a local folder, renaming properly as it does so, runs the updated application and then closes itself.  

The application and updater as well as the files for update are set to not propagate permissions of the parent fiolder and full permission is given to everyone on the network.

Further testing has revealed that the code is failing on the delete line.

Question by:lgropper
    LVL 6

    Expert Comment

    Why don't you rename instead of delete? Then next time you run the updater, delete the old file so you can rename again?

    If File.Exists(MyOldFile) Then File.Delete(MyOldFile)



    LVL 6

    Expert Comment

    Well, after reading your question again, that might not work. I went on the assumption that something from MyCurrentFile was hanging around in memory. But it's worth a try.

    LVL 5

    Accepted Solution

    sounds like application number two is keeping teh context of application one open.  Are you sure that application number one is properly shut down?  do you store the state of the main application in some file, que, etc. that says that it is shut down as per the request of application number 2?  this way you can insure that your application is properly closed and you can ditch the time and pray approach.
    LVL 2

    Expert Comment

    by:anwar ul haque
    You can not delete the application exe untill it is in running state or some other application is accessing it, so make sure that there is no other application is currently accessing it and it is properly shut down, recommened is to write your code in closing event. Delete the application exe from within external exe after some time...add delay and check if file exists then delete it..Hope it will help you

    Anwar ul Haque

    Author Comment

    Thanks, it turns out that I need to put a thread.sleep between the shutdown and the delete so that the delete didn't occur until all threads had been dropped from Application One... thanks a lot!
    LVL 5

    Expert Comment

    Roger that

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now