1

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 work 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?

2 Answers 2

2

The first program left the file open, so the second program cannot delete it.

You need to close the file in the first program.

0
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.