2

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)
Ashish Pancholi
  • 4,569
  • 13
  • 50
  • 88
  • Why not install by right-clicking the install file and "Run as administrator"? It will give administrator privileges and when you start the application, you won't get "Access Denied". – Buhake Sindi Jul 12 '11 at 10:07
  • should be same named, in same directory as `.exe` file. http://msdn.microsoft.com/en-us/library/aa376618(v=VS.85).aspx – Marek Sebera Jul 12 '11 at 10:08
  • Yes I had tried with the same name and in the same directory but did not work. My executable name is .exe and my manifest name is .exe.manifest and I have copied them in the same folder but did not work – Ashish Pancholi Jul 12 '11 at 10:22

3 Answers3

1

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.

Community
  • 1
  • 1
ewall
  • 27,179
  • 15
  • 70
  • 84
  • "ProgramData" and "Program Files" are not the same. "Program Files" is the place for binaries and read only files - as you stated, but ProgramData is Vista's answer to CSIDL_COMMON_APPDATA. Previously, in Windows XP it used "C:\Documents and Settings\All Users\Application Data". – jveazey Jul 16 '11 at 07:50
  • You're totally right, @John L. Veazey... I should read more carefully! Rescinding my (wrong) answer. – ewall Jul 18 '11 at 12:41
0

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?

user207421
  • 305,947
  • 44
  • 307
  • 483
  • I have edited my original post. Please take a look on actual exception – Ashish Pancholi Jul 12 '11 at 10:39
  • @Ashish Pancholi so the user that ran the program didn't have access to that directory. Probably it was a different user than the one who installed the program and you are tangled up in the nightmare of Windows permissions, especially under Vista. You are going to have to review your installation strategy. This is now a Windows question. – user207421 Jul 12 '11 at 10:44
  • I have looked into this issue and after conformed I have started this thread. I got the solution from here - http://stackoverflow.com/questions/1385866/java-run-as-administrator but unfortunately this is not working for me. – Ashish Pancholi Jul 12 '11 at 10:54
  • Try embedding the manifest within the executable using the Manifest Tool (mt.exe) that comes with the Windows SDK. You can find more information here http://stackoverflow.com/questions/2182815/embedding-an-application-manifest-into-a-vb6-exe/6672996#6672996 – jveazey Jul 20 '11 at 01:41
0

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.

Community
  • 1
  • 1
jveazey
  • 5,398
  • 1
  • 29
  • 44