问题
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:
Take
%USERPROFILE%
Take
%APPDATA%
Take
%APPDATA%
and replace%USERPROFILE%
by null. The "rest" should be "/Application Data" or "/Anwendungsdaten" or whateverTake
%ALLUSERSPROFILE%
Add the result of step 3. to it
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