In Linux, I'll usually put user configuration files in $HOME/.myapp and in Windows I'll use APPDATA. So far so good.
What about non-user specific configuration? In linux, I'd put it into /etc
. Is there an equivalent in Windows? Please note I would like to have the service running before any user logs in. Also, in case it plays a role, I'm developing in Java.
Alternatively: I approaching this the wrong way?
You could use ALLUSERPROFILES as a base directory. This environment variable resolves to the C:\\PROGRAMDATA folder in Windows7. Of course you need to add a specific folder for your applications
In summary, you should use the known folder: ProgramData .
To avoid hard coding of paths (and hence why I'm not providing them here) you should always retrieve the value via one of the following methods:
%PROGRAMDATA%
environment variable (you can also use %ALLUSERSPROFILE%
but I consider %PROGRAMDATA%
more meaningful) SHGetKnownFolderPath
, passing the FOLDERID_ProgramData
.System.Environment.GetFolderPath
, passing CommonApplicationData
.This folder is not writeable by non-admins, so depending on your requirements you'll want to create a directory for your program and set the ACLs you need at install time.
Some good information on this topic is provided in the blog post: " Where Should I Write Program Data Instead of Program Files ".
For those interested in using other Known Folders , MSDN provides extensive documentation .
In Windows most "program files" for an app go in C:\\Program Files\\MyApp. The environment variable would be %ProgramFiles%\\MyApp.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.