문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top