Solved

CommonApplicationData folder access is denied in Vista to a Service

Posted on 2008-10-14
4
2,445 Views
Last Modified: 2013-12-17
I have written a windows service that stores configuration settings in an XML file.  I use to store the settings xml file in the program's folder however Vista's new security model does not allow this.  The service runs for all users and should behave the same way for all users since it runs unattended (without a user logging on).  After researching the folder to store shared user data in I found that I should be saving data here:
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

When my service runs howerver I get the exception:
Service cannot be started. System.UnauthorizedAccessException: Access to the path 'I:\ProgramData\settings.xml' is denied.

My questions is - is this the correct directoy to store application specific data in and if so how do I use the Setup Project to give proper permission durring setup to this folder.  If not, where should I write the settings for the service.  Keep in mind that the service writes default settings if they do not exist and normally reads the setings on start.  A seperate exe must write changes to the settings.

   
0
Comment
Question by:ridgeway
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 7

Expert Comment

by:keustermans
ID: 22755861
Under what account does the service run?
0
 
LVL 1

Author Comment

by:ridgeway
ID: 22768479
A user that has admin rights.  Is is possible to prompt the installer to choose a user account at install time using a vs 2005 setup project?  Does it have to run under the actual administrator on Vista?
0
 
LVL 7

Accepted Solution

by:
keustermans earned 500 total points
ID: 22774178
It is possible to allow a user to set the account details at install.  You could run the service under the  local service account, that should   make sure that you have access to the files.  An easier way to solve your issue would be to add an app.Settings file to your project to store your application settings. Only run your service as a local service if it is absolutely necessary as a local service account has higher access rights then you normal administror account.
0
 
LVL 1

Author Comment

by:ridgeway
ID: 22853487
I want to go with the more restrictive accounts and have chosen to store the data here:
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
I found that I could right click on "File System on Target Machine" in the Setup project to add this folder.

However, I have run into one big problem with this.  
On XP 64 Environment.SpecialFolder.CommonApplicationData does not return the (x86) part of the folder, how do I get around this?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question