File.Copy UnauthorizedAccessException
我有一个应用程序需要将一些文件复制到 C:\Program Files 下的目录。
在启用了 UAC 的 Windows 7 上,我在调用 File.Copy 时收到 UnauthorizedAccessException。
我已将应用程序清单添加到我的应用程序中,如下所示:
<?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>
现在,我在运行应用程序时收到 UAC 提示,但它仍然会导致 UnauthorizedAccessException。
有想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像往常一样,这是我做的愚蠢的事情。
有问题的文件是只读的。删除此属性使我的应用程序能够正确工作。
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.