How can I get the name for the user’s profile directory that is shown in Explorer?
A customer wanted to know how they could get the
SHGetLocalizedName function to work. Fortunately, they gave a specific definition of “work”.
We are populating a list of folders, and we want the names to be the same names that appear in Explorer. We are diong it by calling
SHGetLocalizedName, and if it succeeds, doing a
LOAD_LIBRARY_AS_DATAFILE, and then a
LoadString. (If the call to
SHGetLocalizedNamefails, then we just use the raw file system name.) This works for the most part, but not for the user profile. How can we get the correct name for the user profile folder?
The user profile name is not a localized name, which is why
SHGetLocalizedName doesn’t give you any information about it. Instead, that name is dynamically generated based on the user whose profile you are looking at. (It’s not like there’s a giant
usernames.dll which includes the name of every possible user on the planet, and
SHGetLocalizedName says “Oh, yeah, the user is Raymond Chen? That’s string number 31415 in
The way to get the name that Explorer displays for an item is to ask the same data source that Explorer uses: the shell namespace.
And hey, how about that, I already wrote a sample program that shows how to do this, just in the context of a different question, so I’m going to incorporate the existing program by reference. Here you go.