How can I get the path of a Windows “special folder” for a specific user?

前端 未结 4 624
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 12:04

Inside a service, what is the best way to determine a special folder path (e.g., \"My Documents\") for a specific user? SHGetFolderPath allows you to pass in a token, so I a

4条回答
  •  天命终不由人
    2020-11-29 12:51

    This information is stored in the registry in the key "HKEY_USERS\S-1-5-21-616815238-485949776-2992451252-3228\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders".

    The "S-1-5-21-616815238-485949776-2992451252-3218" is the GUID of the user. You need to get this GUID to find the corresponding key and read it.

    In this example they use SHGetFolderPath function you mention and there is a list with all special folders which might be helpful.

    NOTE: Microsoft discourages to use the registry key, since it is still there just for backward compatibility

提交回复
热议问题