0

I have a program that runs as a service and also runs simultaneously as the service front end.

what is the best strategy for storing files and data for both these instances.

the program runs in 3 modes :-

  • Completely as a service
  • Service and front end GUI (ie 2 instances)
  • GUI

In all cases, files and configuration will need to have create / read / write access and accessible in every other mode

ApplicationData, LocalApplicationData, seem user specific, and i don't want the service to run under a user account

CommonApplicationData, i think has restrictions for general users under UAC

CommonProgramFiles ProgramFiles also has restrictions for general users under UAC

however with the last 2 examples there is the options of setting the permissions on install

Does anyone have an elegant solution to this, or can point me in the right direction

Thanks

TheGeneral
  • 79,002
  • 9
  • 103
  • 141
  • if you don't want the service to run under a user account, you're out of luck... you could use c:\temp\, but that's accessible by anyone and then you risk losing files. The best way is to run as a user, and give that user the rights to a specific folder you create for your app. – MaxOvrdrv Apr 05 '13 at 01:41
  • Hrm, the temp directory is definitely not a good option, i'm still debating running the service under the user account, however it seems to defeat the idea of a service, as it will be limited by the users permissions in to degree i guess, and might create more problems then it solves (i'm still trying to get my head around it) – TheGeneral Apr 05 '13 at 02:47

1 Answers1

0

The %ALLUSERSPROFILE% environment variable should suit your needs. It points to C:\Documents and Settings\All Users on WinXP and C:\ProgramData on modern Windows, both of which are for the storage of user-agnostic program data.

Ken Herbert
  • 5,205
  • 5
  • 28
  • 37
  • I guess what your suggesting is to Create the directory under CommonApplicationData and give it the right permissions for all users when installed, i.e. read write create, to cater for UAC enabled systems? – TheGeneral Apr 05 '13 at 02:40
  • You may not even have to change the permissions. By default (on a fresh install of Win7 Pro, at least) C:\ProgramData allows enough permissions to read/write/create/modify attributes for all users. – Ken Herbert Apr 05 '13 at 03:25