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:
impersonate the desired user account before calling
SHGetFolderPath()
.obtain an access token for the desired user account and pass it to
hToken
.