tags:

views:

399

answers:

5
+2  Q: 

All users path?

In C# I can do the following:

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

Which will get me the path to the all users profile.

In C++ I can use the SHGetFolderPath, but it does not seem to have a CSLID for all users. Is there an equlivant function that I can blow the %ALLUSERSPROFILE% out to its path value?

+4  A: 

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

Jeff Yates
+1: Better than my getenv answer!
Rob
A: 

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

Rob
+5  A: 

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

Kirill V. Lyadvinsky
CSIDL_COMMON_APPDATA returns C:\Documents and Settings\All Users\Application Data on my XP machine whereas ALLUSERSPROFILE points to C:\Documents and Settings\All Users. Is ALLUSERSPROFILE always the parent of CSIDL_COMMON_APPDATA?
Rob
`ALLUSERSPROFILE` is `All Users\Application Data` on WinXP. And it is equal to `C:\ProgramData` on Vista.
Kirill V. Lyadvinsky
Good point; you can't assume that there is such a thing as "**the** directory that holds the entire 'all users' profile", or at least I'm not aware of any documentation which states that.
MSalters
A: 

For most purposes, you should be able to use SHGetFolderPath with one of the CSIDL_COMMON_... values (see here for a complete list) to get the subdirectory of the all users' path that you're interested in. (For Windows Vista and above, you can use SHGetKnownFolderPath with one of the FOLDERID_Public... values; see here.)

Josh Kelley
A: 

Note that in certain security situations that folder might not even be a real folder. There not being a CSIDL_ for it is always a strong hint that you're off the beaten path.

Are you sure you're not better off with _APPDATA?

Stu