问题
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
.
来源:https://stackoverflow.com/questions/24822748/shgetfolderpath-returns-path-to-admin-user-account-when-used-in-an-installer