简体   繁体   English

尝试从 C:\ProgramData 访问文件时出现“拒绝访问”

[英]Getting 'Access Denied' when trying to access file from C:\ProgramData

Our clients are frequently reporting issue that they are getting "Access Denied" exception when they used to run application that has been installed with downloaded setup file.我们的客户经常报告他们在使用下载的安装文件安装的应用程序时遇到“访问被拒绝”异常的问题。 Our installer, installs executable on 'Program Files' and creates configuration files at C:\ProgramData.我们的安装程序在“程序文件”上安装可执行文件并在 C:\ProgramData 创建配置文件。 Once installation is done, our application automatically run first time.安装完成后,我们的应用程序会第一次自动运行。 Whenever user going to run it next time, it throws Access is denied as program can not able to access configuration files at C:\ProgramData.每当用户下次运行它时,它会抛出访问被拒绝,因为程序无法访问 C:\ProgramData 的配置文件。

Yes.. "Run as Administrator" is the solution but we can not ask our all paid users to do such.是的..“以管理员身份运行”是解决方案,但我们不能要求所有付费用户都这样做。 I have searched option at can set privileges by some alternative way then manually run executable as "Run as Administrator".我已经搜索了可以通过某种替代方式设置权限的选项,然后以“以管理员身份运行”手动运行可执行文件。

I have found that help page but that's not working for me.我找到了那个帮助页面,但这对我不起作用。 My application is java desktop application so I have created.exe.manifest file and put that manifest file into executable where images and other product's properties files resides.我的应用程序是 java 桌面应用程序,所以我创建了.exe.manifest 文件并将该清单文件放入图像和其他产品属性文件所在的可执行文件中。

Manifest does not work for me and I am still getting "Access Denied" issue.清单对我不起作用,我仍然遇到“拒绝访问”问题。

This is content of manifest file -这是清单文件的内容 -

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
  <assemblyIdentity version="1.0.0.0"
     processorArchitecture="X86"
     name="<product_name>"
     type="win32"/> 
  <description>Description of your application</description> 
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="true"/>
        </requestedPrivileges>
       </security>
  </trustInfo>
</assembly>

How I can attach the application manifest to the executable as I have only copied that manifest where images and other product's properties files resides?我如何将应用程序清单附加到可执行文件,因为我只复制了图像和其他产品属性文件所在的清单?

Is there any thing need to update in manifest file as I have copied as-is content except?清单文件中是否有任何内容需要更新,因为我已按原样复制内容,除了?

Exception --例外 -

java.io.FileNotFoundException: C:\ProgramData\.<poduct_name>\config\<Product_Name>.xml (Access is denied) stacktrace javax.xml.transform.TransformerException: java.io.FileNotFoundException: C:\ProgramData\.<Product_Name>\config\<Product_Name>.xml (Access is denied) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutputHandler(Unknown Source) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source) at com.<Product_Name>.main.dr.a(Unknown Source) at com.<Product_Name>.main.dr.a(Unknown Source) at com.<Product_Name>.main.dr.a(Unknown Source) at com.<Product_Name>.main.h.k(Unknown Source) at com.<Product_Name>.main.ay.run(Unknown Source) Caused by: java.io.FileNotFoundException: C:\ProgramData\.<Product_Name>\config\<Product_Name>.xml (Access is denied) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream. (Unknown Source) at java.io.FileOutputStream. (Unknown Source) ... 7 more --------- java.io.FileNotFoundException: C:\ProgramData\.<Product_Name>\config\<Product_Name>.xml (Access is denied) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream. (Unknown Source) at java.io.FileOutputStream. (Unknown Source) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutputHandler(Unknown Source) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source) at com.<Product_Name>.main.dr.a(Unknown Source) at com.<Product_Name>.main.dr.a(Unknown Source) at com.<Product_Name>.main.dr.a(Unknown Source) at com.<Product_Name>.main.h.k(Unknown Source) at com.<Product_Name>.main.ay.run(Unknown Source) and the cause isjava.io.FileNotFoundException: C:\ProgramData\.<Product_Name>\config\<Product_Name>.xml (Access is denied)

The problem is because the user settings file is stored in the wrong place. 问题是因为用户设置文件存储在错误的位置。

Only executable binaries and related resources belong in the ProgramData directory ("C:\Program Files..."), and this data should only change when a user with administrator rights installs or updates a program installation.只有可执行二进制文件和相关资源属于 ProgramData 目录(“C:\Program Files...”),并且只有当具有管理员权限的用户安装或更新程序安装时,此数据才会更改。 Any configuration or data that the user needs to change must be kept in places where the user has rights to edit, such as their home folder, "My Documents", their HKEY_CURRENT_USER Registry key, or better yet, their AppData directory.用户需要更改的任何配置或数据都必须保存在用户有权编辑的位置,例如他们的主文件夹、“我的文档”、他们的 HKEY_CURRENT_USER 注册表项,或者更好的是,他们的 AppData 目录。

You can read more about these Windows programming requirements for user data storage here , and here is how some people have done this in Java . 您可以 在此处阅读有关用户数据存储的 Windows 编程要求的更多信息,以及 Java 中的一些人如何做到这一点 Hope that helps get you fixed up! 希望对您有所帮助!

On second thought, perhaps using a tool like PROCMON.EXE would help narrow down the specifics of the denial--because it will show you whether the programming is opening the file/directory for reading, writing-with-all-permissions, trying to create a file that already exists, etc.再想一想,也许使用像PROCMON.EXE这样的工具有助于缩小拒绝的具体范围——因为它会告诉你程序是否正在打开文件/目录进行读取、写入所有权限、尝试创建一个已经存在的文件等。

it throws Access is denied它抛出访问被拒绝

Does it really?真的吗?

There is no such exception.没有这样的例外。

What is the actual exception, and the actual message, and what actual line of code is it thrown at?实际的异常是什么,实际的消息是什么,以及它抛出的实际代码行是什么?

The quickest solution is for you to use the xcacls.exe utility or the icacls.exe utility .最快的解决方案是使用xcacls.exe 实用程序icacls.exe 实用程序 Using them, you can give "Everyone" or whomever the permission to read/write/etc configuration files in C:\ProgramData.使用它们,您可以授予“所有人”或任何人在 C:\ProgramData 中读取/写入/等配置文件的权限。

Note: Make sure to only change the permissions on the files you need to access from your program.注意:确保只更改您需要从程序访问的文件的权限。 ProgramData is a system folder and should not be generally accessible. ProgramData 是一个系统文件夹,通常不可访问。

Update: Also, you need to embed the manifest into the executable specifically as a RT_MANIFEST resource.更新:此外,您需要将清单嵌入到可执行文件中,特别是作为 RT_MANIFEST 资源。 This can be easily done with the Manifest Tool (mt.exe) .这可以通过Manifest Tool (mt.exe)轻松完成。 More information on this can be found in this answer .可以在此答案中找到有关此的更多信息。

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

相关问题 尝试访问 Web 应用程序中的文件时“访问被拒绝” - “Access Denied” when trying to access file in web app 尝试调用SQLite驱动程序时不断出现“ IOException:访问被拒绝” - Constantly getting “IOException: Access Denied” when trying to call SQLite driver 尝试在GCE上访问BigQuery时“访问被拒绝” - “Access Denied” when trying to access BigQuery on GCE 尝试复制使用 JGit 拉取的文件时出现“拒绝访问”消息 - “Access Denied” Message when trying to copy file(s) pulled with JGit 尝试写入新文件时,FileNotFoundException(拒绝访问) - FileNotFoundException (Access is denied) when trying to write to a new file 尝试从网站获取网页时访问被拒绝 - Access denied when trying to get webpage from a website 尝试在%AppData%中执行.exe时拒绝访问 - Access denied when trying to execute a .exe in %AppData% 尝试从JFileBrowser访问文件时出现NullPointerException - NullPointerException when trying to access a file from a JFileBrowser 从 Java 应用程序打开 WMV 文件时访问被拒绝 - Access denied when opening WMV file from Java application FileNotFoundException:从 .txt 文件加载数据时“访问被拒绝” - FileNotFoundException: “Access is denied” when loading data from .txt file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM