Windows application data directory

时间秒杀一切 提交于 2019-12-05 17:28:17

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.

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.

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%.

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