All user paths?

In C #, I can do the following:

DirectoryInfo di = new DirectoryInfo(System.Environment.GetEnvironmentVariable("ALLUSERSPROFILE")); 

Which will give me the path to the profile of all users.

In C ++, I can use SHGetFolderPath, but it does not have a CSLID for all users. Is there an equlivant function so that I can infer% ALLUSERSPROFILE% from my path value?

+4
source share
5 answers

Use ExpandEnvironmentStrings to expand the string %ALLUSERSPROFILE% . This method is part of Kernel32.dll .

+3
source

Use SHGetFolderPath with CSIDL_COMMON_APPDATA . Or SHGetKnownFolderPath with Vista with FOLDERID_ProgramData .

Alternatively use .NET native Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

+10
source

For most purposes, you should use SHGetFolderPath with one of the CSIDL_COMMON_... values ​​(see here for the full list) to get a subdirectory of the path of all users that interests you. (For Windows Vista and above, you can use SHGetKnownFolderPath with one of the FOLDERID_Public... values, see here .)

+1
source

Note that in some security situations this folder may not even be a real folder. There will not be CSIDL_, because it is always a strong hint that you have gone astray.

Are you sure you are not better with _APPDATA?

+1
source

You can use the getenv CRT function to get the value of the ALLUSERSPROFILE environment variable in much the same way as for C #.

0
source

All Articles