Started Process can't delete file
I have a program that start another program. In the second program, I try to delete a File. If I run directly the second program, no problem, the file get deleted. But if I start the second program from the first program, I get a System.UnauthorizedAccessException.
My guess is that the second program doesn't get all the access of the first program.
I tried many suggestions I found but none of them worked.
Adding Process.StartInfo.Verb = "runas" didnt work. Adding a manifest file didnt wo开发者_如何学Crk either (or I did it wrong, not sure) I set the .exe of the second file to "Run as Administrator" and it didn't work.Now, how do I fix this?
The first program left the file open, so the second program cannot delete it.
You need to close the file in the first program.
You might be missing a Dispose()
call on the FileStream
(for example) used to access the file in the first program. That could leave the underlying file in use in that program, although you think the object instances associated with it are gone because they are out of scope.
Post some code if you want better feedback.
精彩评论