• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 350
  • Last Modified:

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

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.

Help!
0
lgropper
Asked:
lgropper
1 Solution
 
ctm5Commented:
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)

File.Copy(MyCurrentFile,MyOldFile)

File.Copy(MyNewFile,MyCurrentFile)


ctm5
0
 
ctm5Commented:
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.

ctm5
0
 
mydasxCommented:
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
anwar ul haqueCommented:
Hi
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

Regards
Anwar ul Haque
0
 
lgropperAuthor Commented:
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!
0
 
mydasxCommented:
Roger that
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now