问题描述
我正在使用SHGetFolderPath CSIDL_APPDATA来获取当前用户帐户下应用程序数据文件夹的路径.它可以正常工作,但是如果从安装程序中调用它,则Windows会将其更改为管理员的文件夹!如何从安装程序中获取当前用户的数据文件夹?
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?
推荐答案
SHGetFolderPath()对于此确切情况具有一个hToken
参数.如果hToken
为NULL,则该函数使用与调用线程关联的访问令牌.否则,可以将其设置为另一个用户帐户的访问令牌.
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:
-
在致电
SHGetFolderPath()
之前模拟所需的用户帐户.
impersonate the desired user account before calling
SHGetFolderPath()
.
获取所需用户帐户的访问令牌并将其传递给hToken
.
obtain an access token for the desired user account and pass it to hToken
.
这篇关于在安装程序中使用时,SHGetFolderPath返回管理员用户帐户的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!