收到“访问被拒绝”的消息尝试从 C:\ProgramData 访问文件时

发布于 2024-11-19 14:55:30 字数 3322 浏览 2 评论 0原文

我们的客户经常报告这样的问题:当他们运行已通过下载的安装文件安装的应用程序时,他们会遇到“访问被拒绝”异常。我们的安装程序在“Program Files”上安装可执行文件,并在 C:\ProgramData 中创建配置文件。安装完成后,我们的应用程序将首次自动运行。每当用户下次运行它时,它都会抛出访问被拒绝,因为程序无法访问 C:\ProgramData 中的配置文件。

是的..“以管理员身份运行”是解决方案,但我们不能要求所有付费用户都这样做。我搜索了可以通过某种替代方式设置权限的选项,然后以“以管理员身份运行”手动运行可执行文件。

我发现 帮助页面 但这对我不起作用。我的应用程序是java桌面应用程序,所以我创建了.exe.manifest文件,并将该清单文件放入图像和其他产品属性文件所在的可执行文件中。

清单对我不起作用,我仍然遇到“访问被拒绝”问题。

这是清单文件的内容 -

<?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>

我如何将应用程序清单附加到可执行文件,因为我只复制了图像和其他产品属性文件所在的清单?

当我按原样复制内容时,清单文件中是否有任何需要更新的内容,除了?

例外 -

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)

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. 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.

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.

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

城歌 2024-11-26 14:55:30

问题是因为用户设置文件存储在错误的位置。

只有可执行二进制文件和相关资源属于 ProgramData 目录(“C:\Program Files...”),并且此数据应该仅当具有管理员权限的用户安装或更新程序安装时才会更改。用户需要更改的任何配置或数据都必须保存在用户有权编辑的位置,例如他们的主文件夹、“我的文档”、他们的 HKEY_CURRENT_USER 注册表项,或者更好的是他们的 AppData 目录。

您可以在此处阅读有关这些用户数据存储的 Windows 编程要求的更多信息< /a> 和 这是一些人的做法在Java中。希望这能帮助您解决问题!

再想一想,也许可以使用像 PROCMON.EXE 将有助于缩小拒绝的具体范围 - 因为它会向您显示编程是否正在打开文件/目录以进行读取、具有所有权限的写入、尝试创建一个已经存在的文件等

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. 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.

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. 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.

-残月青衣踏尘吟 2024-11-26 14:55:30

它抛出访问被拒绝

真的吗?

没有这样的例外。

什么是实际异常、实际消息以及它抛出的实际代码行?

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?

清君侧 2024-11-26 14:55:30

最快的解决方案是使用 xcacls.exe实用程序icacls.exe实用程序。使用它们,您可以授予“每个人”或任何人读取/写入 C:\ProgramData 中的配置文件的权限。

注意: 确保仅更改您需要从程序访问的文件的权限。 ProgramData 是一个系统文件夹,一般情况下不应访问。

更新:此外,您需要将清单专门作为 RT_MANIFEST 资源嵌入到可执行文件中。使用 清单工具 ( mt.exe)。有关此问题的更多信息,请参阅此答案。

The quickest solution is for you to use the xcacls.exe utility or the icacls.exe utility. Using them, you can give "Everyone" or whomever the permission to read/write/etc configuration files in 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.

Update: Also, you need to embed the manifest into the executable specifically as a RT_MANIFEST resource. This can be easily done with the Manifest Tool (mt.exe). More information on this can be found in this answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文