SHGetFolderPath returns path to admin user account when used in an installer

我是研究僧i 提交于 2019-12-01 12:20:36

问题


I'm using SHGetFolderPath CSIDL_APPDATA to get path to the application data folder under current user account. It works fine, but if it is called from an installer, Windows change it to administrator's folder! How can I get the current user's data folder from an installer?


回答1:


SHGetFolderPath() has an hToken parameter for this exact situation. If hToken is NULL, the function uses the access token associated with the calling thread. Otherwise it can be set to an access token for another user account.

If the installer is running elevated as an admin, the installer will have to either:

  1. impersonate the desired user account before calling SHGetFolderPath().

  2. obtain an access token for the desired user account and pass it to hToken.



来源:https://stackoverflow.com/questions/24822748/shgetfolderpath-returns-path-to-admin-user-account-when-used-in-an-installer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!