views:

202

answers:

3

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.

A: 

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

tloach
A: 

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.

Pekka
+1  A: 

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.

dsolimano