Kyle
Kyle

Reputation: 17677

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?

Upvotes: 4

Views: 4150

Answers (5)

Kirill V. Lyadvinsky
Kirill V. Lyadvinsky

Reputation: 99565

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

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

Upvotes: 10

Stu
Stu

Reputation: 15769

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?

Upvotes: 1

Josh Kelley
Josh Kelley

Reputation: 58352

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

Upvotes: 1

Rob
Rob

Reputation: 78628

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

Upvotes: 0

Jeff Yates
Jeff Yates

Reputation: 62377

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

Upvotes: 3

Related Questions