A customer reported that their program was failing to start up because the call to
SHGetSpecialFolderPath(CSIDL_ was taking a long time and then eventually returning with
ERROR_. The account that was experiencing this problem had a redirected network profile, "but even if he's redirecting, why would we get the bad net path error? Does calling
SHGetFolderPath actually touch the folder/network? If so, we should probably stop calling this function on the UI thread since network problems could cause our program to hang."
SHGetFolderPath function will access the network if you pass the
CSIDL_ flag, which says "Check if the folder is there, and if not, create it."
The customer had been passing the flag. "We'll remove it. As if our program is going to dictate the creation of the user profile directory."
CSIDL_ flag has been implicated in some other unwanted behavior. For example, if you pass the
CSIDL_ flag when asking for
CSIDL_, this will create a My Pictures directory if there wasn't one before. Generally speaking, you shouldn't be creating these directories as side-effects of other actions. Corporate administrators may suppress creation of folders like Pictures and Videos, but that doesn't do much good if your program casually creates them as part of its startup.
CSIDL values have been superseded by
KNOWNFOLDERID. The flag corresponding to
KF_. If you want to make things even faster, consider passing the
KF_ flag (formerly known as