Windows application data directory

牧云@^-^@ 提交于 2019-12-07 08:18:55

问题


With the environment variable %allusersprofile% I can get the directory where common settings are stored. But most programs store their settings in the sub-folder "anwendungsdaten" (German, application data). Is there a way to get the direct path to this folder? The problem is that its name is language dependent. Thanks.


回答1:


Not sure about what programming language you're using, so I'll assume the basic Windows api. In XP you can call SHGetFolderPath with CSIDL_COMMON_APPDATA as a parameter. It looks like Vista and 7 have a new set of functions that do the same thing, you'd probably want to call SHGetKnownFolderPath.

In Windows Forms, you can use the Application.UserAppDataPath property.




回答2:


I can't see any direct way to get hold of this information directly. If nothing else comes up, the only thing that comes to mind is something hacky that will probably work in 99% of all cases:

  1. Take %USERPROFILE%

  2. Take %APPDATA%

  3. Take %APPDATA% and replace %USERPROFILE% by null. The "rest" should be "/Application Data" or "/Anwendungsdaten" or whatever

  4. Take %ALLUSERSPROFILE%

  5. Add the result of step 3. to it

  6. You should end up with the correct, localized path to the "Appdata" directory of the "All users" profile.

Note: This is untested and I have little experience in this field. But it might work.




回答3:


I'm not aware of any direct way to get it, but if language is your concern then you could grab the end of %APPDATA%, from the last '\' symbol to the end of the string, and append that to %allusersprofile%.



来源:https://stackoverflow.com/questions/2517940/windows-application-data-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!