2

I have a content folder at /Data in my project. When I build it and also when I used the visual studio installation creater, the files are there. When I run the program, it says it is denied access to these files. How do I let the program have access to the file?

The files are in the same directory as the exe. If I just run the file in the debug output folder, it runs fine, just when installed and it goes in the program files.

Shawn Mclean
  • 56,733
  • 95
  • 279
  • 406

3 Answers3

1

In Windows, programs don't have access to files, users do. When a program is run, typically it inherits the access rights of the user running it. It sounds like the NTFS permissions to access the folder are not being set correctly by the installation. Work out what access rights are required, ie read/write and check whether the user has those rights in the /data folder.

If it works in visual studio and when you invoke the .exe in the bin directory, I would guess that you have the requisite permissions in those folders and therefore it functions correctly. You or the user might not have the same NTFS permissions in the program files directory.

The other possibility is that the data files you are loading aren't being deployed by the installer and therefore can't be loaded.

Noel Kennedy
  • 12,128
  • 3
  • 40
  • 57
  • Its deployed and there. The path is setup correctly. I can open and save the data files with notepad or by clicking on it. How do I set permissions on folders in the installer? – Shawn Mclean Dec 18 '11 at 23:45
  • If you have an .msi file, I think you can use a tool called Orca to edit the .msi and get it to alter permissions on folders. – Noel Kennedy Dec 19 '11 at 14:18
1

You cannot store data files in program files, there is an AppData folder for that. Program files is basically read only for security reasons.

Shawn Mclean
  • 56,733
  • 95
  • 279
  • 406
1

To expand a bit further on @Lolcoder 's answer. In my applications I use Environment.GetEnvironmentVariable("ALLUSERSPROFILE") and append my application directorys to that directory. I then use a Custom Commit Action in Windows Installer to run a Batch File to transfer my files from the program directory to the All Users directory.

md "%ALLUSERSPROFILE%\YourApplicationName"
md "%ALLUSERSPROFILE%\YourApplicationName\Data"
cacls "%ALLUSERSPROFILE%\YourApplicationName" /E /P BUILTIN\Users:F
copy "C:\Program Files\YourApplicationName\Data\*.*" "%AllUSERSPROFILE%\YourApplicationName\Data"

This allows me to have application level settings that are not user specific.

Mark Hall
  • 53,938
  • 9
  • 94
  • 111