Localized value from ExpandEnvironmentStrings
In a code, I am using ExpandEnvironmentStrings function to get the value of %USERPROFILE%. I am getting the EN value even on Localized OS such as German. For example, I am getting the value as "C\Users\Administrator". But I am interested in the Localized value such as c:\Benutzer\Administrator.
For now, I am considering using SHGetFileInfo by passing the foldername returned by ExpandEnvironmentStrings. That actually works only with the ultimate folder o开发者_StackOverflowf the path i.e "Administrator" in this case and not "Users". To use SHGetFileInfo, I need to break the path in individual folders and after getting localized value, join the strings.
Is there a better and more appropriate method to get the complete value localized?
You shouldn't be using environmental values to find shell-related folders. You should use SHGetFolderLocation with CSIDL_PROFILE on XP and earlier, or SHGetKnownFolderIDList on Vista and higher with FOLDERID_Profile. I believe both of these will return the localized locations.
The environment variable should be accurate as of the time your program starts up (which is when its environment variables' values are established). That's all ExpandEnvironmentStrings
will look at. It doesn't translate into other languages. If the value of your environment variable is "C:\Users\Administrator," then that's what the API will expand it to.
If you want to get the path to the current user's home directory, call SHGetFolderPath
or SHGetKnownFolderPath
.
精彩评论