views:

136

answers:

3

I'd like to find the directory of the current user profile programatically in C++.

+8  A: 

SHGetSpecialFolderLocation is the best way to get at most of the special paths on Windows. Passed CSIDL_PROFILE it should retrieve the folder you are interested in.

If you are actually interested in the contents of the %UserProfile% environment variable you could try ExpandEnvironmentStrings

Chris Becke
+2  A: 

To cover all user profile scenarios in Windows Vista and up there is SHGetKnownFolderPath. Here is the link to the docs page on it and related functions.

Tom Cabanski