在安装程序中使用时,SHGetFolderPath返回管理员用户帐户的路径 [英] SHGetFolderPath returns path to admin user account when used in an installer

查看:191
本文介绍了在安装程序中使用时,SHGetFolderPath返回管理员用户帐户的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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() 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. 在致电SHGetFolderPath()之前模拟所需的用户帐户.

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

获取所需用户帐户的访问令牌并将其传递给hToken.

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

这篇关于在安装程序中使用时,SHGetFolderPath返回管理员用户帐户的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆