简体   繁体   English

从 Program Files 中读取 dll 时拒绝访问路径,该 dll 实际上是从 nuget 包中获取的

[英]Access to path denied while reading a dll from Program Files which is actually got from a nuget package

Access to path denied error is encountered in Program files (x86) , while working with a DLL that is got from nuget package: AODL for reading ODF files - https://www.nuget.org/packages/AODL/ after I created a MSI file using SETUP Project在使用从 nuget 包获取DLL 时,Program files (x86) 中遇到访问路径被拒绝错误:AODL for reading ODF files - https://www.nuget.org/packages/AODL/ after I created a使用SETUP 项目的MSI 文件

在此处输入图片说明

In the code, I don't suspect the file creation part for I create this file in the user chosen file conversion path but NOT IN PROGRAM FILES folder path :在代码中,我不怀疑我在用户选择的文件转换路径中创建此文件的文件创建部分,但不在PROGRAM FILES 文件夹路径中

File.WriteAllText(targetFileName, sb.ToString(), Encoding.UTF8);

That's why I simply suspect the DLL, please let me know how I could find the error and fix this.这就是为什么我只是怀疑 DLL,请告诉我如何找到错误并修复此问题。

A bunch of directories - both Programm Files, the root directory of the System Drive, Windows - are heavily protected by NTFS rights.一堆目录——包括程序文件、系统驱动器的根目录、Windows——都受到 NTFS 权限的严格保护。 Writing them is usually a plain "no-go".编写它们通常是一个简单的“禁止”。 Unless you run around with full administrative rights - wich only Instalers and very rare Adminsitrative tools should even consider - you will not be able to write there.除非你拥有完全的管理权限——只有安装程序和非常罕见的管理工具应该考虑——否则你将无法在那里写作。

However you indicated this happens on a read .但是您指出这是在read上发生的。 Reads being blocked like that is very unusual.像这样阻止读取是非常不寻常的。 You need to check what rights are set on those folders and why.您需要检查对这些文件夹设置了哪些权限以及原因。 Maybe the installer accidentally copied the rights from your computer, wich only makes sense with your users and groups?也许安装程序不小心从您的计算机复制了权限,这仅对您的用户和组有意义? Maybe Windows or a third party broke those rights?也许 Windows 或第三方破坏了这些权利? Not a lot of options I can think of that could apply here.我能想到的可以适用于这里的选项并不多。

For this application, even for reading the DLLs from the Program Files folder I needed Admin rights so I forced the application to have such rights for execution.对于这个应用程序,即使为了从 Program Files 文件夹中读取 DLL,我也需要管理员权限,所以我强制应用程序拥有这样的执行权限。

The below line for the newly created application manifest file is changed and that solved the issue.新创建的应用程序清单文件的以下行已更改并解决了问题。

<requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />

The fix is explained well in How do I force my .NET application to run as administrator? 如何强制我的 .NET 应用程序以管理员身份运行?

The reasons are stated well in https://stackoverflow.com/a/50588465/129130原因在https://stackoverflow.com/a/50588465/129130 中有很好的说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM