I have an application that needs to copy some files to a directory under C:\Program Files.
On Windows 7 with UAC enabled, I get an UnauthorizedAccessException when calling File.Copy.
I've added a app manifest to my application as follows:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="requireAdministrator"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
I now get a UAC prompt when running the application, but it still results in the UnauthorizedAccessException.
Ideas?
As usual, this was something stupid I was doing.
The files in question were read-only. Removing this attribute allowed my application to work correclty.